61 Ruby interview questions with answers
61 Ruby interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
All Ruby interview questions
What is Ruby and what makes it stand out?
What is the difference between a Symbol and a String in Ruby?
What does `freeze` do in Ruby?
What is the difference between an instance variable (`@`) and a class variable (`@@`) in Ruby?
What is the difference between public, private, and protected methods in Ruby?
What is duck typing in Ruby and why is it considered a strength?
What is a block in Ruby and how does `yield` work?
What is the difference between `proc` and `lambda` in Ruby?
What does the Enumerable module provide in Ruby? Give examples with `map`, `select`, and `inject`.
What is a lazy enumerator in Ruby? When should you use it?
What is a closure in Ruby? Are blocks closures?
What is a module in Ruby? How does it differ from a class?
What is the difference between `include`, `extend`, and `prepend` in Ruby?
What does the Comparable module do in Ruby?
What are open classes (monkey patching) in Ruby? What are the pros and cons?
What is a singleton method in Ruby? How does `self.` relate to the eigenclass?
What is metaprogramming in Ruby? Give a real-world example.
How does `method_missing` work in Ruby? What are the important caveats?
How does `define_method` differ from a regular `def`? When should you use it?
What are hook methods in Ruby? Give examples of `inherited`, `included`, and `extended`.
What is the difference between `send` and `public_send` in Ruby? When should you use each?
What is the exception handling structure in Ruby? How do `begin/rescue/ensure` work?
What is the Ruby exception hierarchy? Why should you not `rescue Exception`?
How do you create a custom exception in Ruby? What are the best practices?
How do `raise` and `retry` work in Ruby? What are the pitfalls of `retry`?
What are RubyGems and Bundler? How do you use a `Gemfile`?
How does garbage collection work in Ruby? What is generational GC?
What are the differences between `==`, `eql?`, `equal?`, and `===` in Ruby?
What is mutability in Ruby? Which types are immutable by default?
What is the difference between `each` and `map` in Ruby? When should you use each?
What is a Fiber in Ruby? How does it differ from a Thread?
What are `attr_accessor`, `attr_reader`, and `attr_writer` in Ruby?
How does the method lookup chain (MRO) work in Ruby when modules are mixed in?
What is a Struct in Ruby? When should you use Struct instead of a class?
What are `class_eval` and `instance_eval` used for in Ruby?
How do `throw`/`catch` differ from `raise`/`rescue` in Ruby?
What do `~>`, `>=`, and `=` mean in a Ruby Gemfile?
Why does Ruby have a GIL (Global Interpreter Lock)? How does it affect concurrency?
What is ObjectSpace in Ruby? When is it used in practice?
What is pattern matching in Ruby (3.0+)? Show examples with `in` and `case/in`.
What is the difference between `nil?`, `empty?`, and `blank?` in Ruby?
What is the difference between `load`, `require`, and `require_relative` in Ruby?
What is the safe navigation operator `&.` in Ruby? How does it differ from `.try`?
How do Symbol#to_proc and the `&` operator work? When do you use `&method(:name)`?
What are `tap` and `then`/`yield_self` in Ruby? How do they differ?
What is the difference between `super` and `super()` in Ruby?
What is the difference between `dup` and `clone` in Ruby?
What is the difference between `alias` and `alias_method` in Ruby?
What is a Refinement in Ruby? How does it differ from monkey patching?
What are `respond_to?` and `is_a?`/`kind_of?` used for in Ruby? When should you use each?
What is method chaining in Ruby? How do you implement a chainable API?
How do you implement a thread-safe Singleton pattern in Ruby?
What is Marshal in Ruby? When should and shouldn't you use it?
How do you implement a custom Enumerator in Ruby? How does `Enumerator.new` work?
What is a Ractor in Ruby (3.0+)? What problem does it solve that Threads cannot?
What is the `# frozen_string_literal: true` magic comment in Ruby? How does it affect performance?
How do you implement safe method chaining with exception handling in Ruby (Railway-Oriented Programming)?
What is `Data.define` in Ruby 3.2? How does it differ from Struct?
How does `yield` differ from taking the block explicitly with `&block`? When do you use each?
How many Puma workers and threads should you configure? How does the GVL affect that decision?
A Puma/Sidekiq process keeps growing in RAM and never gives it back. Is that a memory leak? How do you handle it?