On Aug 28, 11:34 am, "Wolfgang N?dasi-Donner" <ed.oda... / wonado.de>
wrote:
> Trans wrote:
> > Has anyone else every wished #p would passthru it's argument? Ie. Work
> > like this:
>
> >   def p(x)
> >     puts x.inspect
> >     x
> >   end
>
> > Is there any good reason that it shouldn't? I noticed this was in
> > Ruby's source code TODO list once, but it never came to pass for some
> > reason.
>
> > Thanks,
> > T.
>
> I prefer the following modification, because it makes it easy to be a
> voyeur in method chains.
>
> irb(main):001:0> module Kernel
> irb(main):002:1>   def my_p
> irb(main):003:2>     p self
> irb(main):004:2>     self
> irb(main):005:2>   end
> irb(main):006:1> end
> => nil
> irb(main):007:0> %w{a b c d}.my_p.collect{|i|'<'+i+'>'}.my_p.reverse
> ["a", "b", "c", "d"]
> ["<a>", "<b>", "<c>", "<d>"]
> => ["<d>", "<c>", "<b>", "<a>"]
>
> Wolfgang N?dasi-Donner
> --
> Posted viahttp://www.ruby-forum.com/.

Call me crazy, but isn't this thread really about how great it would
be to use Object#tap?

http://moonbase.rydia.net/mental/blog/programming/eavesdropping-on-expressions.html

--
-yossef