Recall & Review
beginner
How do you run a Ruby script named
hello.rb from the command line?You run it by typing
ruby hello.rb in the terminal and pressing Enter.Click to reveal answer
beginner
What does the
ruby command do when running a script?It starts the Ruby interpreter, reads the script file, and executes the Ruby code inside it.
Click to reveal answer
intermediate
Can you run a Ruby script without the
ruby command? If yes, how?Yes, by adding a shebang line
#!/usr/bin/env ruby at the top of the script and making it executable with chmod +x script.rb, then run it with ./script.rb.Click to reveal answer
beginner
What happens if you run
ruby without any script file?Ruby starts an interactive session called IRB (Interactive Ruby), where you can type Ruby code and see results immediately.
Click to reveal answer
intermediate
How do you pass arguments to a Ruby script when running it?
You add the arguments after the script name like
ruby script.rb arg1 arg2. Inside the script, you access them with the ARGV array.Click to reveal answer
What command runs a Ruby script named
app.rb?✗ Incorrect
The correct command to run a Ruby script is
ruby app.rb.What does the
ARGV array contain in a Ruby script?✗ Incorrect
ARGV holds the command line arguments passed to the Ruby script.How can you make a Ruby script executable without typing
ruby before it?✗ Incorrect
Adding a shebang line and making the script executable allows running it directly.
What happens if you type
ruby alone in the terminal?✗ Incorrect
Typing
ruby alone starts IRB, an interactive Ruby shell.Which of these is NOT a way to run a Ruby script?
✗ Incorrect
run script.rb is not a valid command to run Ruby scripts.Explain how to run a Ruby script from the command line and how to pass arguments to it.
Think about the command format and how the script receives extra words after the filename.
You got /4 concepts.
Describe how to make a Ruby script executable without typing 'ruby' before it.
Consider what goes at the top of the file and what permission you change.
You got /3 concepts.