0
0
Rubyprogramming~15 mins

Running scripts with ruby command - Mini Project: Build & Apply

Choose your learning style9 modes available
Running Ruby Scripts with the ruby Command
📖 Scenario: You want to learn how to run simple Ruby scripts using the ruby command in the terminal. This is useful when you write Ruby code in a file and want to see the output by running it.
🎯 Goal: Learn how to create a Ruby script file, add a simple Ruby program, and run it using the ruby command to see the output.
📋 What You'll Learn
Create a Ruby script file named greeting.rb
Write a Ruby program that prints a greeting message
Use the ruby command to run the script and display the output
💡 Why This Matters
🌍 Real World
Running Ruby scripts from files is how developers test and run their Ruby programs in real projects.
💼 Career
Knowing how to run Ruby scripts with the ruby command is essential for Ruby developers, testers, and anyone working with Ruby code.
Progress0 / 4 steps
1
Create a Ruby script file with a greeting message
Create a Ruby script file named greeting.rb and write this exact line of code inside it: puts "Hello, Ruby!"
Ruby
Need a hint?

Use a text editor to create a file named greeting.rb and type puts "Hello, Ruby!" inside it.

2
Add a variable to store the greeting message
In the greeting.rb file, add a variable named message and set it to the string "Hello, Ruby!". Then use puts message to print it.
Ruby
Need a hint?

Assign the string to message and then print it with puts message.

3
Run the Ruby script using the ruby command
Open your terminal or command prompt and run the command ruby greeting.rb to execute the script and see the output.
Ruby
Need a hint?

Use the terminal command ruby greeting.rb to run your script file.

4
Display the output of the Ruby script
Print the output of running ruby greeting.rb. It should show the exact text: Hello, Ruby!
Ruby
Need a hint?

When you run ruby greeting.rb, the terminal should display Hello, Ruby!.