Top Coursera Specialization courses

Learn Ruby Tutorial for Beginners!

Part: Hello World

One of the most basic tasks in any programming language is to display information to the user. To print something to the console so the user can see it, use puts.

puts “I will be printed to the console!”

Everything between the quotation marks will be printed to the console.

You can use either single (') or double (") quotation marks with puts, as long as you are consistent.

Instead of writing puts, you can use the shorter form, p.

    p 'Hello world'

You can also use print to display information. The difference between puts and print is that when you use the puts keyword, Ruby adds a newline(’ \n ‘) at the end. Ruby does not do this with print.

    puts 'Hello World !!!'
    Hello World !!!
    => nil

     print 'Hello World !!!'
     Hello World !!!=> nil

This tutorial is based on Interactive Tutorials license

If you want to submit a tutorial, please do contact us via info at coursesim.

If you want to report a tutorial please contact us in the same way as above so we can adjust or take it down.