Ruby print Method Tutorial

In this section, we will learn what the print() method is and how to use it in Ruby.

Note: we’re assuming you’re familiar with the Ruby puts method.

What is print Method in Ruby?

The print method is used to print out values to the output stream.

It works exactly the same as puts method with the exception that it won’t add newline character to the end of each argument it takes. So that means each value won’t print to a new line, but they will appear right next to each other.

Ruby print Method Syntax:

print value1, value2, value_n

print( value1, value2, value_n)

As you can see, the method takes one or more argument (variables, raw values etc.) And send those values to the output stream.

Note: just like puts method, the use of parentheses is optional.

Example: printing data to the output stream using print method

nickname = "Jack"

first_name = "John"

print first_name, nickname, 50, true

print "***"

print(false, 40, nickname)



Top Technologies