0
0
Rubyprogramming~20 mins

Running scripts with ruby command - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ruby Script Runner Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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
AHello, Ruby!\n10
BHello, Ruby!\n16
CHello, Ruby!\n11
DSyntaxError
Attempts:
2 left
💡 Hint
Remember the order of operations in arithmetic.
Predict Output
intermediate
2: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}!"
ANameError
BHello, Alice!
CARGV[0]
DHello, !
Attempts:
2 left
💡 Hint
ARGV holds command line arguments passed to the script.
🔧 Debug
advanced
2: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()
AArgumentError: wrong number of arguments (given 0, expected 1)
BSyntaxError: unexpected end-of-input
CNoMethodError: undefined method 'greet' for main:Object
DNo error, prints 'Hello, !'
Attempts:
2 left
💡 Hint
Check how many arguments the method expects versus what is given.
Predict Output
advanced
2: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
ASyntaxError
B1\n2\n3
C0\n1\n2
D0\n2\n4
Attempts:
2 left
💡 Hint
The block variable i starts at 0 and goes up to 2.
🧠 Conceptual
expert
2: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?
A3
Bnil
C1
D0
Attempts:
2 left
💡 Hint
The exit method sets the program's exit status code.