Ruby has several methods for outputting data to the console. The most common methods are P, puts, and print. I will check the differences between these methods every time I use them, but I forgot to do it some time later... So record it here. You can find it next time :)
After the puts method is output, it will automatically wrap the line (if the output string itself contains a line break, puts will not add additional line breaks) and will escape. Puts can accept multiple parameters, and each parameter is output into a separate row. Kernel puts = $ stdout. Puts
Print does not wrap By default (so when multiple parameters are accepted, the output is still a whole line) and will not be escaped. Directly Using print will output $ _. But print will be affected by $, (separator) and $ \ (line tail character.
Print "A", "B", "C" # => ABC $, = "," $ \ = "\ n" print "A", "B ", "C" # => A, B, C \ n
Other aspects are similar to puts.
P is basically equivalent to puts obj. inspect.