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 "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 'Hello world'
You can also use
puts keyword, Ruby adds a newline(' \n ') at the end. Ruby does not do this with
puts 'Hello World !!!' Hello World !!! => nil print 'Hello World !!!' Hello World !!!=> nil
Print "Hello, World!" to the console using puts.