Ruby: Print
To print, use p
, puts
, print
.
# ruby a = 5 b = "rabbit" p a, b, 3 # prints each on a new line.
parenthesis optional
p a, b, 3
can be written as
p(a, b, 3)
parenthesis are often not necessary
Difference between puts, p, print
puts
prints in a human readable form, and adds newline after each argument. For example, string is printed without quotes, array are printed without the brackets or separators.p
prints in a technical form. e.g. string include the quotes. This is good for debugging.print
is similar to “puts” but does not add newline.