Challenge - 5 Problems
Ruby Script Runner Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a Ruby script run with ruby command
What is the output when running this Ruby script with
ruby script.rb?Ruby
puts "Hello, Ruby!" puts 5 + 3 * 2
Attempts:
2 left
💡 Hint
Remember the order of operations in arithmetic.
✗ Incorrect
The script prints the string first, then calculates 5 + (3 * 2) = 11.
❓ Predict Output
intermediate2:00remaining
Effect of command line argument on Ruby script output
What will be the output of this Ruby script when run as
ruby greet.rb Alice?Ruby
name = ARGV[0] puts "Hello, #{name}!"
Attempts:
2 left
💡 Hint
ARGV holds command line arguments passed to the script.
✗ Incorrect
ARGV[0] is 'Alice', so the script prints 'Hello, Alice!'.
🔧 Debug
advanced2:00remaining
Identify the error when running this Ruby script
What error will occur when running this Ruby script with
ruby test.rb?Ruby
def greet(name) puts "Hello, #{name}!" end greet()
Attempts:
2 left
💡 Hint
Check how many arguments the method expects versus what is given.
✗ Incorrect
The method greet requires 1 argument but is called with none, causing ArgumentError.
❓ Predict Output
advanced2:00remaining
Output of a Ruby script using a block with ruby command
What is the output of this Ruby script when run with
ruby block.rb?Ruby
3.times do |i| puts i * 2 end
Attempts:
2 left
💡 Hint
The block variable i starts at 0 and goes up to 2.
✗ Incorrect
3.times runs the block 3 times with i = 0,1,2; output is i*2 each time.
🧠 Conceptual
expert2:00remaining
Understanding Ruby script exit status with ruby command
If a Ruby script ends with
exit(3), what will be the exit status code when run with ruby script.rb?Attempts:
2 left
💡 Hint
The exit method sets the program's exit status code.
✗ Incorrect
Calling exit(3) sets the exit status code to 3, which the OS receives.