Hello World program in Ruby language
Writing a Hello World
program in Ruby is as simple as writing a single line in
a file as
puts 'Hello World'
Run the Ruby program
Create a file name as hello.rb
in your favorite editor or through command line editor like vim
.
Although, you can give any name to file. I have used hello
.
By convention, Ruby source files have .rb
file extension.
Then, type following line in the file:
puts 'Hello World' # or puts "Hello World"
Ruby uses '#' symbol as single line comment. |
Run the program in the terminal or shell as:
ruby hello.rb
Hello World
Congrats! You just wrote your first program in Ruby.
Quiz - Hello World
Ruby uses // for for single line comments?
1. true
2. false
We use .ruby as our extension for Ruby programs.
1. true
2. false
Key points to understand
- File extension of Ruby program is
.rb
- To print strings into the standard output (i.e terminal), you can use
puts
, which means “put string”. #
is used as comment operator