Twelve Common Ruby Interview Questions

Jacob Kagon
3 min readMay 23, 2021

I had a few interviews related to my knowledge of Ruby on Rails. After graduating from the Flatiron School, I have mostly been learning more about Javascript, CSS, and algorithms. I haven’t completely forgotten Ruby (which was the first language I've learned), but I could always use a refresher.

I thought I should come up with some questions and answers myself. I’ll start off with some easy ones and work my way towards some trickier ones.

  1. What is OOP?

OOP stands for Object-Oriented Programming. Object-oriented programming is basically a way of organizing code into things called objects. An object contains properties (aka attributes) and methods (or functions). There are four main pillars of OOP. They are abstraction, encapsulation, inheritance, and polymorphism. Abstraction describes how only necessary data is shown. This is important in simplifying the interface of an application. Encapsulation is also used to simplify the interface by enclosing related methods and data in a class. Inheritance describes how you can create a class hierarchy where classes can pass down methods to subclasses. Polymorphism describes how different objects can access the same interface. Each object can provide its own implementation of the interface.

2. What is Ruby?

Ruby is an object-oriented programming language that is dynamically typed and views everything as an object.

3. What is the command to create a Ruby on Rails app?

Rails new

4. What are Ruby gems?

Ruby gems are packages of software. They allow you to extend the functionality of your application.

5. What are the variable types in Ruby (There are four)?

local variable

sentence = "I love Ruby"

global variable

$sentence = "I love Ruby"

instance variable

@sentence = "I love Ruby"

class variable

@@sentence = "I love Ruby"

6. What is binding.pry?

Binding.pry is a ruby gem that allows you to debug your application.

7. Is Ruby statically typed or dynamically typed?

Ruby is dynamically typed. We know this because we can do something like

animal = "cat"
animal = "dog"

8. What are getters and setters in Ruby?

Getters allow access to an instance variable. Setters allow you to set an instance variable.

9. What is the difference between class and instance methods?

Class methods are used on classes, while instance methods are used on instances. Class methods have the keyword self before the name of the method for example:

class Restaurant def self.milkshake    puts "i'm a milkshake" enddef burger 
puts "i'm a burger"
endendRestaurant.order #=> "i'm a milkshake"meal = Restaurant.new meal.burger #=> "i'm a burger"

10. What is Active Record?

Active Record is an ORM (Object Relational Mapping) that matches models with database tables. It allows you to write SQL queries in Ruby code which simplifies your codebase. (Who likes writing vanilla SQL?)

11. What is self in Ruby?

Self refers to the object it is being called on. For example with class methods, when we define a class method, we do:

class Books   def self.read 
@@fav_book = "Harry Potter"
end
end

In this example, because self is being called at the method level, only the class can call self.

Books.read

If self was inside of a method, we would know that self is referring to the same object the method is being called on.

12. Describe the Model View Controller?

The MVC is a design pattern that splits up the handling of data into the model, view, and controller. The model handles the data and logic, the view displays information, and the controller is the middleman between the model and the view. It manages incoming requests and sends and receives data from the model before sending it to the view.

--

--