What is the value of `nums` after this code runs?
nums = [1, 2, 3]
doubled = nums.map { |n| n * 2 }
p numsRead the full question →Every question is hand-checked, every answer comes with an explanation, and your progress builds into a clear picture of where you stand.
Every Ruby question shows its code before you answer, so you are reading real Ruby, not a description of it.
Once you attempt a question you get the reasoning, not just a tick. That matters most on Ruby, where method lookup through modules and prepend, blocks versus procs versus lambdas and their return behaviour, method_missing, mutation of frozen objects, and the singleton class.
Progress is tracked per topic across the 60 Ruby topics, so revision points at the gaps instead of the whole list.
557 Ruby questions right now: 50 easy, 247 medium and 260 hard. That number is read straight from the question table when this page is built, so it is never a rounded marketing figure.
No. Every Ruby question, including its code snippet, its difficulty and its topic, is readable without signing in. You need a free account only to submit an answer, see which option is correct, and read the worked explanation. We keep it that way so the platform stays honest about what you actually got right.
Method lookup through modules and prepend, blocks versus procs versus lambdas and their return behaviour, method_missing, mutation of frozen objects, and the singleton class.
60 distinct topics are tagged on the Ruby questions, including method_missing and respond_to_missing, method lookup and ancestors, method_missing dispatch internals, Proc vs lambda return and arity, mark-sweep and GC.compact, Comparable and spaceship. The topic labels come from the questions themselves, so the list matches what you will actually be asked.
Yes. Reading is free and unlimited. A free account unlocks answering, explanations and progress tracking. Pro (₹199 per month) adds AI explanations and AI-graded guesstimates on top; it is not needed to practise Ruby MCQs.
Rails product companies, internal tooling, and startups that value shipping speed.
These are 12 of the 557 Ruby questions in the library, pulled live from the question table. The snippet, the difficulty and the topic are all here. The answer options and the explanation are not. Those need a free account.
Method lookup through modules and prepend, blocks versus procs versus lambdas and their return behaviour, method_missing, mutation of frozen objects, and the singleton class.
nums = [1, 2, 3]
doubled = nums.map { |n| n * 2 }
p numsRead the full question →h = { a: 1, b: 2 }
h.fetch(:c)Read the full question →class Ghost
def method_missing(name, *args)
"ghost: #{name}"
end
end
g = Ghost.new
puts g.anything # works
m = g.method(:anything) # ???Read the full question →class Roles
%i[admin editor viewer].each do |role|
define_method("#{role}?") { @role == role }
end
def initialize(r) = @role = r
end
u = Roles.new(:editor)
[u.admin?, u.editor?, u.viewer?]Read the full question →a = "pre#{ENV['X']}".freeze
b = "pre#{ENV['X']}".freeze
c = -"pre#{ENV['X']}"
d = -"pre#{ENV['X']}"
# Assume ENV['X'] is unset, so all four have equal content.Read the full question →p "ab" * 3Read the full question →class Bag
include Enumerable
def initialize(*items); @items = items; end
def each; @items.each { |i| yield i }; end
end
puts Bag.new(1, 2, 3).map.classRead the full question →p [1, nil, 2, false, 3].compactRead the full question →0.times do
puts "hi"
endRead the full question →def describe(x)
if x.nil?
"got nil"
elsif x == false
"got false"
else
"got something"
end
endRead the full question →class User
attr_accessor :name
def initialize(n)
name = n
end
end
puts "Hi, #{User.new('Sam').name}"Read the full question →name = "Sam"
puts "Hi #{name.upcase}!"Read the full question →We keep the correct answer, the explanation and the scoring behind sign-in so the platform stays honest, which is why the correct option and the worked explanation for every Ruby question stay behind a free account. Signing in is free and takes a few seconds.
Rails product companies, internal tooling, and startups that value shipping speed.