hello
why does:
puts "Inspect:#{p(myDog)}"
give LESS verbose results than:
p(myDog)
?
is it that p returns an array, and puts only prints the first element of
arrays?
thanks
···
--
Posted via http://www.ruby-forum.com/.
hello
why does:
puts "Inspect:#{p(myDog)}"
give LESS verbose results than:
p(myDog)
?
is it that p returns an array, and puts only prints the first element of
arrays?
thanks
--
Posted via http://www.ruby-forum.com/.
"p x" is a shorthand for "puts x.inspect", i.e. it actually does the printing. The "inspect" method is what actually returns a "verbose" string. I suspect the intent of your first statement was:
puts "Inspect:#{myDog.inspect}"
If you call p during a string interpolation, you can expect the output to appear before the whole strong you've asked it to print, which is probably not what you wanted.
On 05/12/10 02:55, Johny Why wrote:
hello
why does:
puts "Inspect:#{p(myDog)}"give LESS verbose results than:
p(myDog)
?
is it that p returns an array, and puts only prints the first element of
arrays?
--
Matthew
The method #p is meant to be used as a replacement for:
puts obj.inspect
It outputs itself, so you don't want to interpolate its output like
you're doing above. Try this:
print "Inspect: "
puts myDog.inspect
... vs ...
print "p: "
p myDog
Ben
On Sat, Dec 4, 2010 at 6:55 PM, Johny Why <johnywhy@gmail.com> wrote:
why does:
puts "Inspect:#{p(myDog)}"give LESS verbose results than:
p(myDog)