Top 10 Ruby On Rails Interview Questions

Ruby-On-Rails-Interview-question
Top 10 Ruby On Rails Interview question

List fo Ruby on Rails Interview questions.

1) Mention the types of variables available in Ruby Class?

Types of variables available in Ruby Class are,
Local Variables
Global Variables
Class Variables
Instance Variables

2) Explain 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”.

3) Explain what is the difference between put and putc statement?

Unlike the puts statement, which outputs the entire string onto the screen. The Putc statement can be used to output one character at a time.

4) Explain what is a class library in Ruby?

Ruby class libraries consist of a variety of domains, such as thread programming, data types, various domains, etc. These classes give flexible capabilities at a high level of abstraction, giving you the ability to create powerful Ruby scripts useful in a variety of problem domains. The following domains which have relevant class libraries are,
GUI programming
Network programming
CGI Programming
Text processing


5) In Ruby, it explains about the defined operator?

The defined operator tells whether a passed expression is defined or not.  If the expression is not defined, it gives null, and if the expression is defined it returns the description string.

6) Mention what is the difference in scope for these two variables: @@name and @name?

The difference in scope for these two variables is that:
@@name is a class variable
@name is an instance variable


7) Mention what is the syntax for Ruby collect Iterator?

The syntax for Ruby collect Iterator collection = collection.collect.

8) In Ruby code, often it is observed that coder uses a short hand form of using an expression like array.map(&:method_name) instead of array.map { |element| element.method_name }. How this trick actually works?

When a parameter is passed with “&” in front of it. Ruby will call to_proc on it in an attempt to make it usable as a block.  So, symbol to_Proc will invoke the method of the corresponding name on whatever is passed to it. Thus helping our shorthand trick to work.

9) Explain 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.

10) Mention what is the Notation used for denoting class variables in Ruby?

In Ruby,
A constant should begin with an uppercase letter, and it should not be defined inside a method
A local must begin with the _ underscore sign or a lowercase letter
A global variable should begin with the $ sign. An uninitialized global has the value of “nil” and it should raise a warning. It can be referred toywhere in the program.
A class variable should begin with double @@ and have to be first initialized before being used in a method definition


11) Mention 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


12) Mention 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.

13) Mention 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.

14) Mention what is the difference extend and include?

The “include” makes the module’s methods available to the instance of a class, while “extend” makes these methods available to the class itself.

Find more Rails Interview questions and Answes below.

Leave a Reply

Your email address will not be published. Required fields are marked *