0
0
Rubyprogramming~20 mins

IRB for interactive exploration in Ruby - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
IRB Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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
A30
B25
C20
D15
Attempts:
2 left
💡 Hint
Remember that x is first set to 10, then increased by 5, then multiplied by 2.
🧠 Conceptual
intermediate
1:30remaining
What does IRB stand for and what is its main purpose?
Choose the correct description of IRB in Ruby.
AInternal Ruby Builder, a compiler for Ruby programs.
BInteractive Ruby, a tool to write and test Ruby code line by line.
CIntegrated Ruby Backend, a server for Ruby applications.
DInstant Ruby Binary, a Ruby executable file.
Attempts:
2 left
💡 Hint
IRB lets you try Ruby commands one at a time and see results immediately.
🔧 Debug
advanced
2: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
ASyntaxError: unterminated string meets end of file
BNameError: undefined local variable or method `Hello'
CNoMethodError: undefined method `puts'
DTypeError: no implicit conversion of nil into String
Attempts:
2 left
💡 Hint
Check if all quotes are properly closed.
📝 Syntax
advanced
2: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.
A
def square(n):
  return n * n
end
B
def square(n) {
  n * n
}
C
def square(n)
  n * n
end
D
def square n
  n * n
end
Attempts:
2 left
💡 Hint
Ruby methods use def and end keywords without colons or braces.
🚀 Application
expert
2: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?
A[7, 8, 9, 10]
B[3, 6, 9, 12]
C[1, 2, 3, 4]
D[9, 12]
Attempts:
2 left
💡 Hint
First multiply each element by 3, then keep only those greater than 6.