Challenge - 5 Problems
IRB Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this IRB session snippet?
Consider the following IRB commands entered one after another. What will be the output of the last command?
Ruby
x = 10 x += 5 x * 2
Attempts:
2 left
💡 Hint
Remember that x is first set to 10, then increased by 5, then multiplied by 2.
✗ Incorrect
x starts at 10, then x += 5 makes it 15, then x * 2 equals 30.
🧠 Conceptual
intermediate1:30remaining
What does IRB stand for and what is its main purpose?
Choose the correct description of IRB in Ruby.
Attempts:
2 left
💡 Hint
IRB lets you try Ruby commands one at a time and see results immediately.
✗ Incorrect
IRB stands for Interactive Ruby and is used to experiment with Ruby code interactively.
🔧 Debug
advanced2:00remaining
Why does this IRB code raise an error?
In IRB, the following code is entered:
"""
puts 'Hello
"""
What error will IRB show and why?
Ruby
puts 'Hello
Attempts:
2 left
💡 Hint
Check if all quotes are properly closed.
✗ Incorrect
The string starting with a single quote is not closed, causing a syntax error.
📝 Syntax
advanced2:00remaining
Which IRB command correctly defines a method that returns the square of a number?
Select the correct Ruby method definition entered in IRB that returns the square of a given number n.
Attempts:
2 left
💡 Hint
Ruby methods use def and end keywords without colons or braces.
✗ Incorrect
Option C uses correct Ruby syntax for method definition. Option C uses Python style colon and return. Option C uses braces like other languages. Option C misses parentheses which is allowed but less common and can cause ambiguity in IRB.
🚀 Application
expert2:30remaining
What is the value of variable result after this IRB session?
In IRB, the following commands are entered in order:
"""
arr = [1, 2, 3, 4]
result = arr.map { |x| x * 3 }.select { |x| x > 6 }
"""
What is the value of result?
Attempts:
2 left
💡 Hint
First multiply each element by 3, then keep only those greater than 6.
✗ Incorrect
Mapping multiplies each element by 3: [3,6,9,12]. Selecting elements > 6 keeps [9,12].