Home » Ruby programming » Ruby programs

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.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.