Gavin Kistner
12/26/2006 5:46:00 PM
Dermot Moynihan wrote:
> Learned a lot from all your posts. Even that p can be written instead of
> puts!
For what it's worth, the 'p' method spits out the result of calling
#inspect on each argument, while the 'puts' method spits out the result
of calling #to_s on each argument.
For numbers, the two are identical; not so for other beasts. For
example:
puts "Hello"
#=> Hello
p "Hello"
#=> "Hello"
puts ['a',1,false,/hello/]
#=> a
#=> 1
#=> false
#=> (?-mix:hello)
p ['a',1,false,/hello/]
#=> ["a", 1, false, /hello/]
For many objects, the result of calling #inspect is a string that is
more like source code (though it doesn't have to be) and generally
gives you a better idea of the structure of the object.