Hello world


The required "Hello World!" example. Create the file called hello.rb with the following content. Then go to the command line, to the same directory where you have the file hello.rb saved and type ruby hello.rb. It will print "Hello World!" to your screen.

What you can see here is that if you would like to have some text in your program you need to put them between quotes (") and you can use the puts function to print something to the screen. Any text between quotes is called a "string".


examples/intro/hello.rb
puts "Hello World!"

ruby hello.rb

Just to clarify, unlike in some other programming languages, in Ruby you can use either double-quotes or single-quotes to mark the beginning and the end of a string, but of course it has to be the same on both sides.

examples/intro/hello_single.rb
puts 'Hello World!'