19 Ruby & Ruby on Rails Interview Questions and Answers
Ruby and Ruby on Rails have recently emerged as some of the most sought after skills in web development. Even if you’re a general or junior-developer, you’ll most likely be expected to have some knowledge and experience with the ruby language and rails framework. The average Ruby developer salary is currently around $80k/year, while particularly skilled and senior developers can fetch almost twice that. Furthermore, many of the web’s most popular sites, including Hulu, Github, Twitter, Groupon, Yellow Pages, are built on the rails framework. Set against this backdrop, it’s no wonder there’s been an explosion of interest in learning ruby.
Keeping that in mind, below is a list of ruby interview questions from around the web that you should run through before your upcoming developer interview to get your mind running. This list is by no means exhaustive, and prospective employees should be prepared to handle much more complex questions and exercises than these.
Remember that the best interview questions are open ended and have no definitive answers – a good interviewer knows this and will be looking for your thought process and problem solving skills, rather than the ‘correct’ answer. That being said, there are still some straight forward questions that any Rails programmer should be able to answer and discuss. Yes, many of these questions are relatively simple but being able to explain them in plain english may be more difficult than you think. To quote Albert Einstein, ‘If you can’t explain it simply, you don’t understand it well enough’
Open Ended Questions
- 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.
- 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.
- What are Gems and which are some of your favorites?
- Short answer: 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.
General Knowledge
- 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.
- 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.
- Be prepared to discuss what this actually means in real life, and when you would use a module vs. a class and why.
- 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.
- You should be able to explain in detail how object structure and behavior relate to their common class, and why this is so important in Ruby (see question 1).
- 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.

Initializing instance variables of the class Order.
- How does a symbol differ from a string?
- Short answer: symbols are immutable and reusable, retaining the same object_id.
- Be prepared to discuss the benefits of using symbols vs. strings, the effect on memory usage, and in which situations you would use one over the other.
- 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.
- 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.
- You can also take the long route and create them manually.
- 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.
- Beyond the simple textbook definition, be able to describe an example of a class and how you would use class and instance variables within it, and how they relate to issues of class inheritance.
- Explain some of the looping structures available in Ruby?
- For loop, While loop, Until Loop.
- Be able to explain situations in which you would use one over another.
Model Associations
- Explain the difference between a has_one and belongs_to association:
- has_one: Indicates a direct 1:1 relationship between objects where each instance of a model contains one instance of another model.
- A product has_one provider, a customer has_one order.
- belongs_to: Represents the inverse of a has_one (or has_many) association.
- ex) An order belongs_to a customer.
- A good way to remember this is that if a table has foreign keys, its model should have a belongs_to association.
- Be able to explain the difference and describe an example of how you would assign these associations to two related models.
- Explain a polymorphic association:
- Polymorphic associations allow a model to belong to more than one other model through a single association.

A polymorphic association schematic, from Rubyonrails.org
- Here, the class Picture belongs_to both Employee and Product, but does so through a single association rather than through multiple.
- Be sure to know an appropriate situation to create a polymorphic association, such as creating a comment model associated with multiple other models (articles, photos, etc.). The advantage of using polymorphism here is that it allows you to create a single comment model, rather than separate models for each one (PhotoComment model, ArticleComment model, etc.)
Procs, Lambdas, and Methods
- What is a Proc?
- Procs, short for procedures, act similar to blocks, but can be saved as variables and reused. Think of them as blocks you can call over and over again on multiple arrays.
- Explain an instance when you would use a proc over a block. Read more here
- 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. Read more here
- What are the three levels of method access control for classes and what do they signify? What do they imply about the method?
- Public, protected, and private.
- Public methods can be called by all objects and subclasses of the class in which they are defined in.
- Protected methods are only accessible to objects within the same class.
- Private methods are only accessible within the same instance.
- Be able to explain why this does (or doesn’t matter), and when you would want to set a method as private.
- Explain what functional testing is:
- Functional testing in Rails allows you to test the response of various actions contained in a controller. Using the Rails default test library, mini test, functional tests use a collection of assert statements that will tell your testing library to expect a certain response based on a control request passed in (either a get, post, patch, put, head, delete request).
- The two example tests below show functional tests for making sure the post and delete requests in our UsersController properly create and destroy users. The functional tests do this by making sure the requests result in a change in the User.count and that they then redirect to the desired pages.
- Other helpful tips:
- Aside from being able to demonstrate proficient knowledge, you should also be able to demonstrate your enthusiasm for RoR by highlighting your individual contributions to the community. Be sure to be able to share and discuss your favorite Ruby or Rails blogs, your positions on contested topics within the Rails community, or any open source contributions you’ve made. This is also your opportunity to show off any independent projects you’ve been working on or any Gems you’ve published.
Ace Your Ruby Interview
While it’s great to be able to speak to all of these concepts and show that you can carry an in-depth technical conversation, there’s probably nothing more valuable than having a solid portfolio of apps and a demonstrable level of skill. Being able to speak to these issues is important, and verbal communication skills are highly indicative of future job performance. However, showing that you can apply and manipulate these concepts is much more difficult than speaking to them in generalities. If you’re already a great RoR developer, most of these topics will be like second nature to you. If you’re still a junior-level developer, spend some time not only reviewing and understanding these concepts, but also making sure you can properly utilize them in a real world setting.
No comments:
Post a Comment