What is print method in Ruby?
Overview
The print method is used to print values to the console. It is similar to the puts and $stdout methods.
Syntax
print data
Parameter
data: The data we want to print to the console.
Return value
The value returned is printed data on the console.
Code example
Let's look at the code below:
# create some variablesname = "Okwuidili"age = 1000# print data to the consoleprint nameprint "\n#{age}"print "\nwelcome to edpresso!"
Code explanation
- Lines 2 and 3: We create some variables and initialize them with some data.
- Lines 6 to 8: We use the print method to print data to the console, including the data of the variables we created.