Ruby on Rails interview questions – Part one – Ruby


This is the first article on the RoR interview questions. The purpose is not necessary to be used to ‘cheat’ on an interview, but to present some tricky things in Ruby and RoR.

Some (the majority) of the questions do not yet have answers. I will be filling the blanks.. soon 🙂

What is the duck typing?

The duck typing can be seen as one of the ruby implementation of polymorphism. The principle is: “If it walks like a duck and quacks like a duck, I would call it a duck.”. Below is an example of this principle (from

class ADuck
    def quack()
        puts "quack A";

class BDuck
    def quack()
        puts "quack B";

# quack_it doesn't care about the type of the argument duck, as long
# as it has a method called quack. Classes A and B have no
# inheritance relationship.
def quack_it(duck)

a =
b =

Is ruby a scripted/compiled/interpreted/etc language?

Ruby is an scripted language. It means the code is intepreted by an interpretor on runtime (‘on-the-fly’).

What kind of typed language is ruby? (strongly, weakly, etc..)

Ruby is a strongly, dynamically and implicitly language.

What is the DRY principle?

DRY stands for “Do not Repeat Yourself”.

Ruby general OOP

Are the numbers objects in Ruby?

Everything is an object in Ruby.

Why = 4?

What is the difference between symbol and string?

What is the difference between 0, nil and false?

What is the difference between @something, $something and @@something?

Does Ruby have class methods? Can you access an instance variable from a class method?

Do you have the possibility to access a private instance variable from a class? What OOP principle would this violate?

Is it possible to define a method just for an instance of a class? What is ruby ghost class?

Can you rewrite a ruby standard function (like String#length)?

What is the difference between clone and dup?

  a = []
  b = a.clone
  c = a.dup
  p a.frozen?, b.frozen?, c.frozen?
    # => true, true, false

  class Ary < Array
    def foo
      @foo = "foo"
    def inspect
      (@foo ? @foo : "") + " " + super

  a =
  b = a.clone
  c = a.dup
  p a.inspect, b.inspect, c.inspect
    # => "foo []", "foo []", " []"

What are singleton methods?

Singleton methods are defined on individual objects, not classes. Example below.

class Dog

rover =
fido =

def rover.speak
  puts "Red Rover"

rover.speak  # => "Red Rover"
fido.speak   # => NoMethodError

What are: ri, irb?

What is reflection? How does ruby support reflection?

What is ObjectSpace?

What is the difference between object context and class context?

What are blocks? What is Proc? What is the difference?

What does the keyword yeld? Implement a function similar to function in Ruby

What is code eval?

Give some examples of ruby object hooks

Ruby exceptions

How is the exception handling mechanism implemented in Ruby?

When is the finally block executed?

Ruby containers

What is the difference between select, collect, reject, inject?

Ruby naming conventions

What is the difference between method_1, method_2!, method_3?

Ruby modules, mixins

What is the difference between extend, require, include and select?

Can a method be dynamically added to an object?

How is multiple inheritance emulated in ruby?

How is namespace managed in Ruby?

Does Ruby support multiple inheritance?

No, it does not. The multiple inheritance is modeled by mixins (see next qs).

What is the use of modules?

What are mixins?

Ruby garbage collector


I hope this proves usefull for the future ruby employee 🙂 The list remains open, please send me your comments on these questions.

One Response

  1. […] the “RoR interview questions” sequel(part one here) , these are the Rails concepts and technologies questions. Enjoy […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: