Prepare Interview

Exams Attended

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address
Check our LIVE MOCK INTERVIEWS

Ruby On Rails Interview Questions and Answers

Freshers / Beginner level questions & answers

Ques 1. What is Ruby On Rails?

  1. Ruby on Rails is an open source full-stack web application framework written in the Ruby Programming Language. Rails is capable of gathering information using pages and applications from the web server and can interact with a database and can retrieve information from the database.

Is it helpful? Add Comment View Comments
 

Ques 2. Why Ruby on Rails?

1.CRUD (convention over configuration) 
2. DRY Principal (Do not repeat Your self )
3. Gems and Plugins
4. Pure OOP Concept
5. Scaffolding
6.. Rest Support
7.Action Mailer
8. Rake support
9. open source
10.Rpsec Suppot for testing

Is it helpful? Add Comment View Comments
 

Ques 3. Explain how (almost) everything is an object in Ruby.

  • This is a simple question based on complex concept. Here’s your chance to show off your theoretical knowledge and demonstrate that you can have an in depth conversation on class hierarchies, inheritance, methods, encapsulation, polymorphism, and more.

  • Explaining this could take an hour or a few minutes – there’s no single correct answer here, save from being able to demonstrate your familiarity with OOP concepts.

Is it helpful? Add Comment View Comments
 

Ques 4. What’s your favorite testing tool?

The specific answer here is probably not important in and of itself – What’s important is that you can demonstrate familiarity with at least several testing tools, and be able to discuss their individual advantages and weaknesses. Never ventured outside of Rails default testing tools? Take some time to familiarize yourself with tools such as Rspec, FactoryGirl, Capybara, and Cucumber.

Is it helpful? Add Comment View Comments
 

Ques 5. What are Gems and which are some of your favorites?

Gems are packaged bits of Ruby code that you can install to extend or add functionality to your app.
Be sure to be able to discuss a list of your favorite gems, why you like them, and any customizations you like to add. This is also a good opportunity to highlight any gems you may have published.

Is it helpful? Add Comment View Comments
 

Ques 6. What is a class?

You should easily be able to explain not only what a class is, but how and when you would create a new one as well as what functionality it would provide in the larger context of your program.

Is it helpful? Add Comment View Comments
 

Ques 7. What is the difference between a class and a module?

The straightforward answer: A module cannot be subclassed or instantiated, and modules can implement mixins.

Is it helpful? Add Comment View Comments
 

Ques 8. What is an object?

Textbook answer here is that an object is an instance of a class and has state, behavior, and identity. In a plain text example, you can say that a truck and a car are both objects of the class Vehicle, or that apple and pear are both objects of the class Fruit.

Is it helpful? Add Comment View Comments
 

Ques 9. How would you declare and use a constructor in Ruby?

Constructors are declared via the initialize method and get called when you call on a new object to be created.

Using the code snippet below, calling Order.new acts as a constructor for an object of the class Order.

class Order
  def initialize(customer, meal, beverage)
    @customer = customer
    @meal = meal
    @beverage = beverage
  end
end

Is it helpful? Add Comment View Comments
 

Ques 10. How does a symbol differ from a string?

Symbols are immutable and reusable, retaining the same object_id.

Is it helpful? Add Comment View Comments
 

Ques 11. How and when would you declare a Global Variable?

Global variables are declared with the ‘$’ symbol and can be declared and used anywhere within your program. You should use them sparingly to never.

Is it helpful? Add Comment View Comments
 

Ques 12. How would you create getter and setter methods in Ruby?

Setter and getter methods in Ruby are generated with the attr_accessor method. attr_accessor is used to generate instance variables for data that’s not stored in your database column.

Is it helpful? Add Comment View Comments
 

Ques 13. Describe the difference between class and instance variables?

  • Class variables are created with the prefix ‘@@’ and are shared by all objects in a class.

  • Instance variables are created with the prefix ‘@’ and belong to a single object within a class.

Is it helpful? Add Comment View Comments
 

Ques 14. Example some of the looping structures available in Ruby?

For loop, While loop, Until Loop.

Is it helpful? Add Comment View Comments
 

Ques 15. What is a lambda?

Lambdas are very similar to procs in terms of functionality. However, they have a few key differences. Lambdas check the number of arguments passed and will return an error if you try to pass the wrong number (while procs set extra variables to nil). The other difference is that lambdas can handle a return function, whereas procs will return an error.

Is it helpful? Add Comment View Comments
 

Ques 16. What are Class Variables? How to define them?

Class variables are created using the @@ prefix to denote the variable as class level. 

It works just like any other variable, however in the case of inheritance it works more like a static variable that is accessed across all variable instances.

Another example can be found here:

class DemoClass 
 @@my_var = nil
  def initialize
    @@my_var = "hello world"
  end
  def my_var
    puts @@my_var
  end
end
class Demo2Class < DemoClass
  def initialize
    @@my_var = "goodbye world"
  end
end
demo1 = DemoClass.new
demo1.my_var
demo2 = Demo2Class.new
demo2.my_var
demo1.my_var
The output would be as shown below:
hello world
goodbye world
goodbye world

Is it helpful? Add Comment View Comments
 

Ques 17. How to define Instance variables?

Instance variables are defined using single @ symbol.

@foo = "Hello"

Within a class they can be declared as below:

class Animal
 attr_accessor :name, :age
end

Next you can query an object instance to find which instance variables it has.

anim = Animal.new
anim.instance_variables 
=> [ ]
anim.name="John"
anim.age = 3
 => [:@age, :@name] 

In the above case we did not put the @ symbol before the instance variables but it is implied. 

Is it helpful? Add Comment View Comments
 

Ques 18. What is the difference between ‘&&’, ‘AND’ and ‘&’ operators?

The ‘&&’ and ‘and’ are both logical and statements. They ‘&&’ operator has higher precedence though. Here’s an example of illustrate this in more detail:

foo = 3
bar = nil
a = foo and bar
# => nil
a
# => 3
a = foo && bar
# => nil
a
# => nil
Notice how the statement ‘a = foo and bar’ actually behaves like ‘(a = foo) and bar’

Is it helpful? Add Comment View Comments
 

Ques 19. Does Ruby support Multiple Inheritence?

Ruby does not support multiple inheritance.

Is it helpful? Add Comment View Comments
 

Ques 20. How can you define a Constant in Ruby on Rails?

Create a new file as shown below under: config/initializers/my_constants.rb

COLORS = ['white', 'red', 'green']

Is it helpful? Add Comment View Comments
 

Ques 21. What is the default access modifier for a method?

By default all methods are public, except the initialize(constructor) method.

You can make methods private using this declaration within your class:

class MyClass
    def method_public_here
    end
    PRIVATE# all methods that follow will be made private: not accessible for outside objects
    def method_private_here
    end
  end

Is it helpful? Add Comment View Comments
 

Ques 22. Define the Rails MVC implementation with an example.

The MVC framework is an age-old architecture pattern that works very well for most applications. Rails has adopted the MVC pattern in its inherent design.

Stated Simply:

a) Model — is where the data is — the database

b) Controller — is where the logic is for the application

c) View — is where the data is used to display to the user

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

Related interview subjects

REST API interview questions and answers - Total 52 questions
Unix interview questions and answers - Total 105 questions
SDLC interview questions and answers - Total 75 questions
Apache Kafka interview questions and answers - Total 38 questions
Language in C interview questions and answers - Total 80 questions
ANT interview questions and answers - Total 10 questions
Nature interview questions and answers - Total 20 questions
Ruby On Rails interview questions and answers - Total 74 questions
Business Analyst interview questions and answers - Total 40 questions
HTML interview questions and answers - Total 27 questions
Hadoop interview questions and answers - Total 40 questions
iOS interview questions and answers - Total 52 questions
HR Questions interview questions and answers - Total 49 questions
C++ interview questions and answers - Total 142 questions
Cryptography interview questions and answers - Total 40 questions
JSON interview questions and answers - Total 16 questions
CSS interview questions and answers - Total 74 questions
XML interview questions and answers - Total 25 questions
Ethical Hacking interview questions and answers - Total 40 questions
Android interview questions and answers - Total 14 questions
ChatGPT interview questions and answers - Total 20 questions
Data Structures interview questions and answers - Total 49 questions
Zend Framework interview questions and answers - Total 24 questions
Fashion Designer interview questions and answers - Total 20 questions
©2023 WithoutBook