Programming Languages

Ruby interview questions

Interviewers often probe a candidate's understanding of Ruby's object model, its powerful metaprogramming capabilities, and how to write idiomatic, clean, and efficient Ruby code. They look for a grasp of core OOP principles, blocks/procs/lambdas, and common data structures, often through practical coding challenges.

16 questions (5 easy · 6 medium · 5 hard), each with what a strong answer covers and where people lose the point. Free to read, no account.

On this page (16 questions)
  1. 1.Explain the difference between string interpolation and concatenation in Ruby. When would you prefer one over the other?
  2. 2.Describe the primary use cases for Arrays and Hashes in Ruby. Provide a simple example for each.
  3. 3.What is 'truthiness' in Ruby? Provide examples of truthy and falsy values.
  4. 4.Explain the difference between the `each` and `map` (or `collect`) iterators in Ruby. When would you use one over the other?
  5. 5.What is `attr_accessor` in Ruby, and why is it useful? How does it relate to `attr_reader` and `attr_writer`?
  6. 6.Differentiate between a class and a module in Ruby. When would you choose one over the other?
  7. 7.Explain the concept of inheritance versus mixins in Ruby. Provide a scenario where each would be appropriate.
  8. 8.What are the key differences between blocks, Procs, and Lambdas in Ruby? Provide an example illustrating their return behavior.
  9. 9.Explain the meaning and context of the `self` keyword in Ruby. Provide examples of where `self` refers to different things.
  10. 10.How does `method_missing` work in Ruby, and what are its common use cases and potential pitfalls?
  11. 11.What is a singleton class (or eigenclass) in Ruby, and how does it relate to defining methods on a single object?
  12. 12.Describe the Ruby object model, including how objects, classes, and modules are related and how method lookup works.
  13. 13.Explain how to dynamically define methods in Ruby at runtime. Provide an example using `define_method`.
  14. 14.Differentiate between `instance_eval` and `class_eval` in Ruby, and provide use cases for each.
  15. 15.Explain the `**` (double splat) operator in Ruby for keyword arguments. How does it work for both capturing and passing arguments?
  16. 16.Discuss the use of global variables (`$VAR`) in Ruby. What are the best practices and potential issues?

1.Explain the difference between string interpolation and concatenation in Ruby. When would you prefer one over the other?

Warm-up

What a strong answer covers

  • Define string interpolation as embedding expressions within a string literal using `#{}`.
  • Define string concatenation as joining two or more strings using `+` or `<<`.
  • Explain that interpolation is generally preferred for readability and performance when building complex strings.
  • Mention that concatenation can be useful for simple, fixed string additions or when building strings incrementally in a loop (using `<<` for efficiency).

Where people lose the point

  • Not knowing that `+` creates new string objects, potentially impacting performance in loops.
  • Failing to mention that `<<` modifies the string in place, which is more efficient for incremental building.
  • Incorrectly stating that interpolation is always slower or faster without context.
Link to this question

2.Describe the primary use cases for Arrays and Hashes in Ruby. Provide a simple example for each.

Warm-up

What a strong answer covers

  • Explain Arrays as ordered, integer-indexed collections of objects, suitable for lists where order matters.
  • Provide an example of an Array storing a list of items, e.g., `['apple', 'banana', 'cherry']`.
  • Explain Hashes as unordered (or insertion-ordered in modern Ruby), key-value pair collections, suitable for mapping unique keys to values.
  • Provide an example of a Hash storing associated data, e.g., `{ name: 'Alice', age: 30 }`.

Where people lose the point

  • Confusing the ordered nature of Arrays with the key-value nature of Hashes.
  • Incorrectly stating that Hashes are completely unordered in modern Ruby versions (they are insertion-ordered since 1.9).
  • Providing examples that don't clearly illustrate the primary use case for each data structure.
Link to this question

3.What is 'truthiness' in Ruby? Provide examples of truthy and falsy values.

Warm-up

What a strong answer covers

  • Define truthiness as the concept of values evaluating to `true` or `false` in a boolean context (e.g., `if` statements).
  • State that in Ruby, only `false` and `nil` are falsy.
  • Explain that all other values, including `0`, empty strings `''`, and empty arrays `[]`, are considered truthy.
  • Provide clear examples demonstrating both truthy and falsy values in an `if` condition.

Where people lose the point

  • Incorrectly identifying `0`, empty strings, or empty arrays as falsy.
  • Confusing Ruby's truthiness rules with those of other languages (e.g., JavaScript).
  • Failing to explicitly state that `false` and `nil` are the *only* falsy values.
Link to this question

4.Explain the difference between the `each` and `map` (or `collect`) iterators in Ruby. When would you use one over the other?

Warm-up

What a strong answer covers

  • Describe `each` as an iterator that executes a block for each element in a collection and returns the original collection.
  • Explain that `each` is primarily used for side effects, such as printing or modifying external state.
  • Describe `map` (or `collect`) as an iterator that executes a block for each element and returns a *new* array containing the results of the block for each element.
  • Explain that `map` is used when you want to transform a collection into a new collection of the same size.

Where people lose the point

  • Incorrectly stating that `each` returns a new array of transformed elements.
  • Confusing the return values of the two methods.
  • Not clearly articulating the purpose (side effects vs. transformation) for each iterator.
Link to this question

5.What is `attr_accessor` in Ruby, and why is it useful? How does it relate to `attr_reader` and `attr_writer`?

Warm-up

What a strong answer covers

  • Explain `attr_accessor` as a convenient method that automatically defines both a getter (reader) and a setter (writer) method for an instance variable.
  • Describe its usefulness in reducing boilerplate code for common attribute access patterns.
  • Differentiate `attr_reader` as defining only a getter method, allowing read-only access.
  • Differentiate `attr_writer` as defining only a setter method, allowing write-only access.

Where people lose the point

  • Incorrectly stating that `attr_accessor` creates the instance variable itself (it only creates the methods).
  • Confusing the roles of `attr_reader` and `attr_writer`.
  • Failing to explain *why* it's useful (boilerplate reduction).
Link to this question

6.Differentiate between a class and a module in Ruby. When would you choose one over the other?

Core

What a strong answer covers

  • Explain that a `Class` is a blueprint for creating objects, supports inheritance, and can be instantiated.
  • Explain that a `Module` cannot be instantiated and does not support inheritance in the same way; its primary uses are for mixins and namespaces.
  • Describe mixins as a way to share behavior across classes (multiple inheritance of behavior) without traditional class inheritance.
  • Describe namespaces as a way to group related classes, modules, and constants to prevent naming collisions.
  • Provide scenarios: use a class when you need to create objects with state and behavior; use a module for shared functionality (mixins) or code organization (namespaces).

Where people lose the point

  • Stating that modules can be instantiated or have instances.
  • Confusing the purpose of modules with traditional class inheritance.
  • Not clearly explaining both mixin and namespacing roles of modules.
Link to this question

7.Explain the concept of inheritance versus mixins in Ruby. Provide a scenario where each would be appropriate.

Core

What a strong answer covers

  • Define inheritance as an 'is-a' relationship where a subclass inherits methods and attributes from a single superclass, promoting code reuse and polymorphism.
  • Define mixins (via modules) as a way to achieve 'has-a' or 'can-do' relationships, allowing a class to include behavior from multiple modules without single-inheritance limitations.
  • Scenario for inheritance: `Dog < Animal` (a Dog *is an* Animal, sharing core animal behaviors).
  • Scenario for mixin: `User include Authenticatable` (a User *can be* authenticated, adding authentication behavior).
  • Emphasize that Ruby supports single inheritance for classes but multiple inheritance of behavior through modules.

Where people lose the point

  • Suggesting that Ruby supports multiple class inheritance.
  • Not clearly distinguishing between 'is-a' and 'has-a' / 'can-do' relationships.
  • Providing scenarios that don't clearly illustrate the appropriate use of each concept.
Link to this question

8.What are the key differences between blocks, Procs, and Lambdas in Ruby? Provide an example illustrating their return behavior.

Core

What a strong answer covers

  • Explain that blocks are anonymous code chunks passed to methods, not objects themselves, and are temporary.
  • Describe `Proc` as an objectified block, allowing it to be stored and passed around, with 'loose' argument handling and a `return` that exits the *enclosing method*.
  • Describe `Lambda` as a special type of `Proc` with 'strict' argument handling (raises `ArgumentError`) and a `return` that exits *only the lambda itself*.
  • Provide a code example demonstrating the different return behaviors of a Proc and a Lambda when called from within a method.

Where people lose the point

  • Incorrectly stating that blocks are objects.
  • Confusing the argument handling rules for Procs vs. Lambdas.
  • Misunderstanding or misrepresenting the scope of `return` within Procs and Lambdas.
Link to this question

9.Explain the meaning and context of the `self` keyword in Ruby. Provide examples of where `self` refers to different things.

Core

What a strong answer covers

  • Define `self` as a special variable that always refers to the *current object* (the receiver of the current method call or the current context).
  • Explain that inside an instance method, `self` refers to the instance of the class.
  • Explain that inside a class method (defined with `self.method_name` or `ClassName.method_name`), `self` refers to the class itself.
  • Explain that in the top-level scope, `self` refers to the `main` object (an instance of `Object`).
  • Provide code examples for each context to illustrate the changing value of `self`.

Where people lose the point

  • Confusing `self` with `this` from other languages without explaining Ruby's specific context rules.
  • Incorrectly stating that `self` always refers to the class.
  • Failing to provide clear examples for different contexts.
Link to this question

10.How does `method_missing` work in Ruby, and what are its common use cases and potential pitfalls?

Core

What a strong answer covers

  • Explain that `method_missing` is a hook method called by Ruby when an object receives a message for a method it does not define or inherit.
  • Describe its parameters: `method_name` (symbol), `*args` (array of arguments), and `&block` (optional block).
  • Common use cases: implementing DSLs, proxy objects, dynamic finders (e.g., `find_by_name` in ActiveRecord), and delegating calls.
  • Potential pitfalls: performance overhead, making code harder to debug, masking typos, and potential security vulnerabilities if not handled carefully.
  • Mention the importance of also overriding `respond_to_missing?` for proper introspection.

Where people lose the point

  • Not mentioning `respond_to_missing?` which is crucial for proper behavior with `respond_to?`.
  • Overlooking the performance implications or debugging challenges.
  • Failing to explain the parameters `method_name`, `*args`, and `&block`.
Link to this question

11.What is a singleton class (or eigenclass) in Ruby, and how does it relate to defining methods on a single object?

Core

What a strong answer covers

  • Define a singleton class as an anonymous, hidden class that Ruby creates for every object.
  • Explain that methods defined directly on a single object (e.g., `obj.define_singleton_method`) are actually added to that object's singleton class.
  • Describe how the singleton class sits in the inheritance chain *between* the object itself and its actual class, influencing method lookup.
  • Illustrate how this mechanism allows for object-specific behavior without affecting other instances of the same class.
  • Provide an example of defining a method on a single object and accessing its singleton class.

Where people lose the point

  • Confusing the singleton class with the object's regular class.
  • Incorrectly stating that singleton methods are added directly to the object's class.
  • Failing to explain its position in the method lookup chain.
Link to this question

12.Describe the Ruby object model, including how objects, classes, and modules are related and how method lookup works.

Hard

What a strong answer covers

  • Explain that everything in Ruby is an object, and every object is an instance of a class (even classes are objects of the `Class` class).
  • Describe the inheritance chain: an object's class inherits from its superclass, forming a hierarchy up to `BasicObject`.
  • Detail the role of modules: they can be mixed into classes (using `include` or `prepend`), inserting themselves into the method lookup chain.
  • Explain the method lookup path: Ruby searches the object's singleton class, then its class, then any modules included in that class (in reverse order of inclusion for `include`), then the superclass, and so on up the hierarchy.
  • Mention `Object#method_missing` as the final fallback if a method is not found.

Where people lose the point

  • Incorrectly describing the order of module inclusion in the method lookup chain (e.g., confusing `include` with `prepend`).
  • Failing to mention the `singleton_class` as the first place Ruby looks for methods.
  • Not clearly articulating that `Class` and `Module` are themselves classes/objects.
Link to this question

13.Explain how to dynamically define methods in Ruby at runtime. Provide an example using `define_method`.

Hard

What a strong answer covers

  • Explain that dynamic method creation allows you to define methods programmatically during program execution, rather than at compile time.
  • Describe `define_method` as a method (available in `Module` and `Class`) that takes a method name (Symbol or String) and a block (or `Proc`) as arguments.
  • Illustrate with an example: defining getter/setter-like methods for a list of attributes using `define_method` within a class.
  • Discuss use cases such as creating DSLs, generating boilerplate code, or adapting to external data structures.
  • Mention the context of the block passed to `define_method` (it executes in the context of the instance).

Where people lose the point

  • Confusing `define_method` with `method_missing`.
  • Providing an example that doesn't clearly demonstrate runtime method creation.
  • Not explaining the context (`self`) within the block passed to `define_method`.
Link to this question

14.Differentiate between `instance_eval` and `class_eval` in Ruby, and provide use cases for each.

Hard

What a strong answer covers

  • Explain `instance_eval` as a method that executes a block of code in the context of a *specific object instance* (`self` becomes that object).
  • Describe `instance_eval`'s use cases: defining singleton methods, accessing private instance variables/methods of an object, or modifying an object's state from outside its class.
  • Explain `class_eval` (also `module_eval`) as a method that executes a block of code in the context of a *class or module* (`self` becomes that class/module).
  • Describe `class_eval`'s use cases: dynamically adding methods or constants to a class/module, modifying class definitions at runtime, or creating DSLs within a class context.
  • Provide distinct code examples for both `instance_eval` and `class_eval`.

Where people lose the point

  • Confusing the `self` context for `instance_eval` vs. `class_eval`.
  • Incorrectly stating that `instance_eval` can add class methods directly to a class.
  • Failing to provide clear, separate use cases for each method.
Link to this question

15.Explain the `**` (double splat) operator in Ruby for keyword arguments. How does it work for both capturing and passing arguments?

Hard

What a strong answer covers

  • Explain that `**` is used with keyword arguments, which are key-value pairs passed to methods.
  • Describe its use in *capturing* keyword arguments: when used in a method definition (e.g., `def my_method(a:, **options)`), it collects all unassigned keyword arguments into a Hash.
  • Describe its use in *passing* keyword arguments: when used in a method call (e.g., `other_method(**hash)`), it expands a Hash into keyword arguments.
  • Provide an example demonstrating both capturing and passing keyword arguments using `**`.
  • Mention that keyword arguments provide more clarity and flexibility than positional arguments for options.

Where people lose the point

  • Confusing `**` with `*` (single splat) for positional arguments.
  • Incorrectly stating that `**` works with regular positional arguments.
  • Failing to provide clear examples for both capturing and passing.
Link to this question

16.Discuss the use of global variables (`$VAR`) in Ruby. What are the best practices and potential issues?

Hard

What a strong answer covers

  • Define global variables (`$VAR`) as variables accessible from anywhere in a Ruby program, across all classes, modules, and methods.
  • Explain potential issues: increased coupling, difficulty in testing, reduced readability, and potential for unexpected side effects due to global state modification.
  • Discuss best practices: generally avoid global variables due to the issues mentioned, preferring local variables, instance variables, class variables, or constants.
  • Mention specific, rare cases where they might be acceptable (e.g., `$LOAD_PATH`, `$DEBUG`, or for very specific, truly global configuration that is read-only after initialization).
  • Suggest alternatives like configuration objects, dependency injection, or module-level constants for managing shared state.

Where people lose the point

  • Advocating for widespread use of global variables.
  • Not clearly articulating the negative impacts on maintainability and testability.
  • Failing to suggest viable alternatives to global variables.
Link to this question
No account needed

Answer one real Ruby question now

A question a Ruby panel actually asks, answered out loud, scored on what you said and how you said it. Under two minutes, and nothing to sign up for.

Explain the difference between string interpolation and concatenation in Ruby. When would you prefer one over the other?

We never store the audio. Your answer is deleted within 24 hours unless you save the result.

How Ruby answers get judged

The weights a Ruby interviewer is holding, whether or not they say so out loud. Round Zero scores your practice answers against exactly these, and quotes your own words back as the evidence for each.

Technical Accuracy

40%

The answer demonstrates a precise and accurate understanding of Ruby syntax, semantics, and core concepts. No factual errors or misunderstandings.

Conceptual Understanding

30%

The answer goes beyond surface-level definitions, explaining the 'why' and 'how' behind Ruby features, including their underlying mechanisms and implications.

Idiomatic Ruby & Best Practices

20%

The answer reflects an understanding of idiomatic Ruby patterns, common conventions, and best practices for writing clean, maintainable, and efficient Ruby code.

Clarity & Conciseness

10%

The answer is well-structured, easy to understand, and directly addresses the question without unnecessary jargon or verbosity. Examples are clear and illustrative.

Related Programming Languages skills

All skills →

Now say them out loud

You have read what strong Ruby answers contain. The next thing that moves the needle is producing one under time, out loud, and finding out where it falls apart.

  • These questions asked back, with follow-ups
  • Flashcards for the ones you keep missing
  • A scored mock that quotes your own answers

Browse every skill

Practising Ruby: common questions

What Ruby interview questions should I practice?
Start with the core areas Ruby interviewers probe: Explain the difference between string interpolation and concatenation in Ruby. When would you prefer one over the other; Describe the primary use cases for Arrays and Hashes in Ruby. Provide a simple example for each.; What is 'truthiness' in Ruby? Provide examples of truthy and falsy values.. This page outlines strong answers and common mistakes, and the scored path drills each one with follow-ups.
Is the Ruby practice free?
Yes. The Ruby path runs free inside Round Zero: lessons, practice questions and flashcards. Drills are unlimited on every plan, free included. So is the full scorecard. Free also covers 3 complete scored interviews, no card.
How is this different from a Ruby question list?
A static list gives you questions with no feedback. Round Zero runs a live scored practice that probes your actual answers, rotates difficulty, and tells you exactly what to fix, grounded in a Ruby rubric.
How should I prepare for a Ruby interview?
Learn the concepts, drill the questions until answers come fast, then prove it in a scored mock. Round Zero sequences all three so you know you are ready, not just that you read about Ruby.
How is a Ruby answer scored?
Ruby answers are scored on technical accuracy, conceptual understanding, idiomatic ruby & best practices, clarity & conciseness, with evidence quoted from what you actually said, so feedback is specific instead of generic praise.