One of the standard themes of Ruby beginner articles is "Differences between
putsoutputs with line breaks
pdisplays the object as is
pis displayed with
It is a pity that there are many descriptions such as (only those that remain).
"" With" is probably about String objects.
What does "as is" mean? ?? ??
It's a shame that many articles don't have links, although you can clearly see the difference by looking at the official reference. (I'll also give you the
Here are just a few points I would like you to keep in mind. The object must be stringified in order to be output, but how to stringify it is important.
puts is a bit complicated.
There is also a process that "objects that react to
to_ary are arrayed with this first ", but classes with
to_ary (not to be confused with
to_a) are rare, so even if you do not know at first I think it's okay.
Anyway, it's important to know about
to_s to understand these methods.
The link above is a link to each method of the
Object class, but
to_s are overridden in many classes, in which case the method that is actually overridden is the one that is actually used.
So, for example, to see what an array looks like with the
p method, you have to look at Array # inspect.