Top Ruby Developer Interview Preparation Guide
Download PDF

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:

Table of Contents:

Top  Ruby Developer Job Interview Questions and Answers
Top Ruby Developer Job Interview Questions and Answers

1 :: Tell me how can you declare a block in Ruby?

In Ruby, the code in the block is always enclosed within braces ({}). You can invoke a block by using “yield statement”.

2 :: Do you know about Dig, Float and Max?

☛ Float class is used whenever the function changes constantly.
☛ Dig is used whenever you want to represent a float in decimal digits.
☛ Max is used whenever there is a huge need of Float.

3 :: Explain me what is the purpose of RJs in Rails?

RJs is a template that produces JavaScript which is run in an eval block by the browser in response to an AJAX request. It is sometimes used to define the JavaScript, Prototype and helpers provided by Rails.

4 :: Tell me what is Mixin in Rails?

Mixin in Ruby offers an alternative to multiple inheritances, using mixin modules can be imported inside other class.

5 :: What is interpolation in Ruby?

Ruby Interpolation is the process of inserting a string into a literal. By placing a Hash (#) within {} open and close brackets, one can interpolate a string into the literal.

6 :: Tell us the types of variables available in Ruby Class?

Types of variables available in Ruby Class are,

☛ Local Variables
☛ Global Variables
☛ Class Variables
☛ Instance Variables

7 :: Tell me what is Rails Migration?

Rails Migration enables Ruby to make changes to the database schema, making it possible to use a version control system to leave things synchronized with the actual code.

8 :: Do you know when self.up and self.down method is used?

When migrating to a new version, self.up method is used while self.down method is used to roll back my changes if needed.

9 :: Tell me what is Rails Active Record in Ruby on Rails?

Rails active record is the Object/Relational Mapping (ORM) layer supplied with Rails. It follows the standard ORM model as

☛ Table map to classes
☛ Rows map to objects
☛ Columns map to object attributes

10 :: Explain me the log that has to be seen to report errors in Ruby Rails?

Rails will report errors from Apache in the log/Apache.log and errors from the Ruby code in log/development.log.

11 :: What is the difference between a single quote and double quote?

A single-quoted strings don’t process ASCII escape codes, and they don’t do string interpolation.

12 :: Tell me how you can list all routes for an application?

To list out all routes for an application you can write rake routes in the terminal.

13 :: Can you list out the few features of Ruby?

☛ Free format – You can start writing from program from any line and column
☛ Case sensitive – The uppercase and lowercase letters are distinct
☛ Comments – Anything followed by an unquoted #, to the end of the line on which it appears, is ignored by the interpreter
☛ Statement delimiters- Multiple statements on one line must be separated by semicolons, but they are not required at the end of a line.

14 :: Please explain the three levels of access control for Ruby methods?

In Ruby, methods may either be public, protected, or private. Public methods can be called by anyone. Protected methods are only accessible within their defining class and its subclasses. Private methods can only be accessed and viewed within their defining class.

15 :: Tell me what is the function of garbage collection in Ruby on Rails?

The functions of garbage collection in Ruby on Rails includes

☛ It enables the removal of the pointer values which is left behind when the execution of the program ends
☛ It frees the programmer from tracking the object that is being created dynamically on runtime
☛ It gives the advantage of removing the inaccessible objects from the memory, and allows other processes to use the memory

16 :: Can you please explain what is the difference between String and Symbol?

They both act in the same way only they differ in their behaviors which are opposite to each other. The difference lies in the object_id, memory and process tune when they are used together. Symbol belongs to the category of immutable objects whereas Strings are considered as mutable objects.

17 :: Explain me what is the role of Rails Controller?

The Rails controller is the logical center of the application. It faciliates the interaction between the users, views, and the model. It also performs other activities like

☛ It is capable of routing external requests to internal actions. It handles URL extremely well
☛ It regulates helper modules, which extend the capabilities of the view templates without bulking of their code
☛ It regulates sessions; that gives users the impression of an ongoing interaction with our applications

18 :: Tell me what is Polymorphic Association in Ruby on Rails?

Polymorphic Association allows an ActiveRecord object to be connected with Multiple ActiveRecord objects. A perfect example of Polymorphic Association is a social site where users can comment on anywhere whether it is a videos, photos, link, status updates etc. It would be not feasible if you have to create an individual comment like photos_comments, videos_comment and so on.

19 :: Do you know what are the types of caching used in rails, what are they?

There are primarily three types of caching used in Rails.

1. Page Caching

Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the webserver (i.e. Apache or NGINX) without having to go through the entire Rails stack.

2. Action Caching

Page Caching cannot be used for actions that have before filters - for example, pages that require authentication. This is where Action Caching comes in. Action Caching works like Page Caching except the incoming web request hits the Rails stack so that before filters can be run on it before the cache is served. This allows authentication and other restrictions to be run while still serving the result of the output from a cached copy.

3. Fragment Caching

Dynamic web applications usually build pages with a variety of components not all of which have the same caching characteristics. When different parts of the page need to be cached and expired separately you can use Fragment Caching.

20 :: Tell me what is the difference between calling super and calling super()?

A call to super invokes the parent method with the same arguments that were passed to the child method. An error will therefore occur if the arguments passed to the child method don’t match what the parent is expecting.

A call to super() invokes the parent method without any arguments, as presumably expected. As always, being explicit in your code is a good thing.

21 :: What is the difference between a gem and a plugin in Ruby?

☛ Gem: A gem is a just ruby code. It is installed on a machine, and it’s available for all ruby applications running on that machine.
☛ Plugin: Plugin is also ruby code, but it is installed in the application folder and only available for that specific application.

22 :: Tell us what is the difference between redirect and render in Ruby on Rails?

☛ Redirect is a method that is used to issue the error message in case the page is not issued or found to the browser. It tells browser to process and issue a new request.
☛ Render is a method used to make the content. Render only works when the controller is being set up properly with the variables that require to be rendered.

23 :: Tell me what is ORM (Object-Relationship-Model) in Rails?

ORM or Object Relationship Model in Rails indicate that your classes are mapped to the table in the database, and objects are directly mapped to the rows in the table.

24 :: What is the difference between Procs and Blocks?

The difference between Procs and Blocks,

☛ Block is just the part of the syntax of a method while proc has the characteristics of a block
☛ Procs are objects, blocks are not
☛ At most one block can appear in an argument list
☛ Only block is not able to be stored into a variable while Proc can

25 :: Tell us how would you implement hash in Ruby internally?

The purpose of a hash function is to convert a given a key into an integer of limited range. In order to reduce the range, we use a technique called the division method. In the division method, the key is divided by the size of the storage and the remainder is the location inside that table where a record can be stored.

But in real life programming the keys includes strings, objects, etc as well. This is solved by using a one-way hash function over the key and then applying the division method to get the location. The hash function is a mathematical function that takes a string of any length and produces a fixed length integer value. The hash data structure derives it's name from this hashing mechanism. Ruby uses the murmur hash function and then applies the division method with a prime number M, which Ruby determines based on the table size that is needed for storage.
Ruby Developer Interview Questions and Answers
74 Ruby Developer Interview Questions and Answers