There are print, puts, p, pp, printf, etc. when outputting String with ruby. For example
print 'Hello World.'
If you enter, the characters inside''will be output.
Output result
1. Hello World.
It is displayed without line breaks in the print method.
puts
In addition to print, if you use puts, it will be output with a line break at the end.
puts 'Hello'
puts 'World.'
Output result
1. Hello
2. World.
p
The output result of the p method is enclosed in "" and displayed as it is. It is used for debugging because the object type information, line feed code, special characters, etc. are output as they are.
p 'Hello World.'
p Hello World.
Output result
1. "Hello World."
2. Hello World.
pp
For pp, output with moderate indentation and line breaks can be obtained.
Recommended Posts