Ruby Developer

  Home  Web Development  Ruby Developer


“Ruby Developer Frequently Asked Questions in various Ruby Developer job interviews by interviewer. The set of questions are here to ensures that you offer a perfect answer posed to you. So get preparation for your new job interview”



74 Ruby Developer Questions And Answers

21⟩ As you know ruby provides four types of variables. List them and provide a brief explanation for each?

The four types of variables in Ruby are as follows:

☛ Global variables begin with $ and are accessible from anywhere within the Ruby program regardless of where they are declared—it stands to reason that they must be handled with care.

☛ Local variables begin with a lowercase letter or an underscore. The scope of a local variable is confined to the code construct within which it is declared.

☛ Class variables begin with @@ and are shared by all instances of the class that it is defined in.

☛ Instance variables begin with @ and are similar to class variables except that they are local to a single instance of a class in which they are instantiated.

 132 views

22⟩ Please explain what is MVC and why do we use it?

MVC stands for Model View Controller.

Model is the data structure that your program uses.

The View is the part that interacts with the screen or the next level up.

The Controller generally processes data between the model and view.

For example, a model will define your table in the database, the controller will dictate what to do behind the scenes and what to display in the view next. The view part generates the user interface which presents data to the user.

Let’s take an example of creating a form. The submit form will be a view file, from that view file, when you click on the submit button it goes to the respective controller where you have written your business code about what happens on submitting the application/form, and from that controller the data will be saved in the database.

Thus MVC helps to split up the the business logic, database access and presentation. This is very useful in most web applications, and now lately into software/desktop applications.

 123 views

24⟩ Please explain each of the following operators and how and when they should be used ==, ===, eql?, equal?

== – Checks if the value of two operands are equal (often overridden to provide a class-specific definition of equality).

=== – Specifically used to test equality within the when clause of a case statement (also often overridden to provide meaningful class-specific semantics in case statements).

eql? – Checks if the value and type of two operands are the same (as opposed to the == operator which compares values but ignores types). For example, 1 == 1.0 evaluates to true, whereas 1.eql?(1.0) evaluates to false.

equal? – Compares the identity of two objects; i.e., returns true iff both operands have the same object id (i.e., if they both refer to the same object). Note that this will return false when comparing two identical copies of the same object.

 168 views

25⟩ Explain me what is the difference between Symbol and String?

☛ The symbol in Ruby on rails act the same way as the string but the difference is in their behaviors that are opposite to each other.

☛ The difference remains in the object_id, memory and process time for both of them when used together at one time.

☛ Strings are considered as mutable objects. Whereas, symbols, belongs to the category of immutable.

☛ Strings objects are mutable so that it takes only the assignments to change the object information. Whereas, information of, immutable objects gets overwritten.

☛ String objects are written like

p: “string object jack”.object_id #=>2250 or

p: “string object jack”.to_sym.object_id #=> 2260, and

p: “string object jack”. to_s_object_id #=> 2270

☛ Symbols are used to show the values for the actions like equality or non-equality to test the symbols faster then the string values.

 150 views

26⟩ Explain me what is the naming convention in Rails?

☛ Variables: For declaring Variables, all letters are lowercase, and words are separated by underscores

☛ Class and Module: Modules and Classes uses MixedCase and have no underscore; each word starts with a uppercase letter

☛ Database Table: The database table name should have lowercase letters and underscore between words, and all table names should be in the plural form for example invoice_items

☛ Model: It is represented by unbroken MixedCase and always have singular with the table name

☛ Controller: Controller class names are represented in plural form, such that OrdersController would be the controller for the order table.

 135 views

27⟩ Can you explain me how Rails implements Ajax?

Ajax powered web page retrieves the web page from the server which is new or changed unlike other web-page where you have to refresh the page to get the latest information.

Rails triggers an Ajax Operation in following ways

☛ Some trigger fires: The trigger could be a user clicking on a link or button, the users inducing changes to the data in the field or on a form

☛ Web client calls the server: A Java-script method, XMLHttpRequest, sends data linked with the trigger to an action handler on the server. The data might be the ID of a checkbox, the whole form or the text in the entry field

☛ Server does process: The server side action handler does something with the data and retrieves an HTML fragment to the web client

☛ Client receives the response: The client side JavaScript, which Rails generates automatically, receives the HTML fragment and uses it to update a particular part of the current

 120 views

28⟩ Tell me what is the difference between the Observers and Callbacks in Ruby on Rails?

☛ Rails Observers: Observers is same as Callback, but it is used when method is not directly associated to object lifecycle. Also, the observer lives longer, and it can be detached or attached at any time. For example, displaying values from a model in the UI and updating model from user input.

☛ Rails Callback: Callbacks are methods, which can be called at certain moments of an object’s life cycle for example it can be called when an object is validated, created, updated, deleted, A call back is short lived. For example, running a thread and giving a call-back that is called when thread terminates

 136 views

29⟩ Explain me what are the limits of Ruby on Rails?

Ruby on Rails has been designed for creating a CRUD web application using MVC. This might make Rails not useful for other programmers. Some of the features that Rails does not support include

☛ Foreign key in databases

☛ Linking to multiple data-base at once

☛ Soap web services

☛ Connection to multiple data-base servers at once

 122 views

31⟩ Please explain what are some advantages of using Ruby?

You want a programmer who can really play to the strengths of the Ruby programming language. Here are some of the key advantages of this language:

☛ Pure Object-Oriented Language: Everything in Ruby is an object—even methods, classes, and booleans. This greatly simplifies things from the coder’s perspective and opens up a range of possibilities.

☛ Open-Source: Ruby is 100% free and open-source, with a large and enthusiastic community that can be tapped into as a resource.

☛ Metaprogramming: Ruby is widely considered to be one of the best programming languages out there for metaprogramming, or the ability to write code that can act on other code instead of data.

☛ Clean and Simple Syntax: The syntax is simple and concise, which allows developers to solve complex programs with fewer lines of code. It also helps that the code is human readable, and easy to follow.

 135 views

32⟩ Tell me what are blocks and procs?

A block is basically Ruby’s version of a closure—a block of code that can be wrapped up into a proc (a type of function) that can then be stored in a variable or passed to a method and run when desired. Blocks can syntactically be written as blocks of code between { } or the do and end keywords. The standard way to create a proc is depicted in the code block below.

> my_proc = Proc.new { |arg1| print "#{arg1}! " }

 122 views

33⟩ Tell me what is the difference between Ruby 1.9 and Ruby 2.0?

Ruby 2.0 differs in various ways, such as:

FASTER

Ruby 2 has a few patches that dramatically improve performance. The biggest of these is a substantial optimization to Kernel#require, which speeds up Rails startup dramatically. Ruby 2 also has improved GC, VM optimizations, and improvements to floating point operations.

UTF-8 BY DEFAULT

All Ruby scripts now default to UTF-8 encoding. This makes the #encoding: utf-8 magic comment no longer necessary.

LITERAL SYMBOL ARRAY SYNTAX

You can now use %i and %I to make an array of symbols:

LAZY ENUMERATORS

Ruby 2 introduces the concept of a lazy Enumerable object. A lazy Enumerable will not consume excess memory, and will process individual elements as needed instead of the entire array/range passed to it.

 153 views

34⟩ Tell me what does ruby name refers to?

☛ Ruby names refer to the classes, variables, methods, constants and modules that help in the creation of the program.

☛ These are the names that distinguish other names with the specified ruby names that are being mentioned above.

☛ Ruby names are useful and used to be written as it is shown. They are useful in the context of writing the programs and while generating the module.

☛ Ruby names refer to the classes that has to be built and through which the objects will be declared, and methods that will perform on the data that is given.

☛ The names are reserved such that they can’t be used anywhere else and for any other purpose. The name that is used can be in lower or upper case, letter, number or an underscore

 134 views

38⟩ Do you know what is the defined operator?

Define operator states whether a passed expression is defined or not. If the expression is defined, it returns the description string and if it is not defined it returns a null value.

 126 views