As with most languages, we always want to start with a “Hello World” program.
Remember, this is to make sure everything is working, as much as it is to learn the programming language.
For simplicity’s sake, we’re going to use the online editor: https://www.jdoodle.com/execute-ruby-online or https://www.onlinegdb.com/online_ruby_compiler
puts "Hello World"
You will notice right away that in Ruby, we don’t have a print or similar function. Instead, we use the puts
command, and follow it with a literal string.
If you split our string into two strings like below:
puts "Hello", "World"
Then we’re going to get an interesting effect, where each string is printed on a separate line.
// code output
Hello
World
However, I can concatenate my strings to get them to print on a single line:
puts "Hello" + " " + "World"
With this, we should be good to move forward with programming in Ruby.
Your First Ruby Program was originally found on Access 2 Learn