Ruby program to print Hello World!

Printing Hello World! in Ruby: This is the first ruby program in which we are going to print a simple message (Hello World!) using print and puts commands.
Submitted by Hrithik Chandra Prasad, on August 06, 2019

Printing Hello World! In Ruby

To print text (Hello World! Or anything else), we use following two methods,

  1. puts : The word "puts" stands for put string. It adds a newline after the string.
  2. print : The functionality of this method is same as of puts but it does not adds newlines implicitly like puts.

Variables used: No variables are required as we only have to print the statements. We don't have to store anything.

Ruby code to print "Hello World!"

=begin 
Ruby program to print Hello World.
=end

puts "Hello World!"
print "Hello World!"
puts "Hello World!"

Output

Hello World!
Hello World!Hello World!

Code explanation:

The code illustrates an example to print a string "Hello World!" in Ruby programming language. This uses the puts and print methods to print the string and output "Hello world" using these methods.

You can observe in the output that the print method is not providing a newline and two statements are printing together. Though, both the methods have the same functionality but still use them wisely.

Ruby Basic Programs »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.