To print text (Hello World! Or anything else), we use following two methods,
- puts : The word "puts" stands for put string. It adds a newline after the string.
- 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!"
Output
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.
need an explanation for this answer? contact us directly to get an explanation for this answer