From: Trans Date: 2007-08-29T07:07:18+09:00 Subject: Re: More convenient #p? On Aug 28, 10:55 am, Yossef Mendelssohn wrote: > On Aug 28, 11:34 am, "Wolfgang N�dasi-Donner" > 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"] > > ["", "", "", ""] > > => ["", "", "", ""] > > > 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-ex... Similar idea. But #p is for debugging. Who would want to go through all the trouble of ".tap{ p ... }." when "p ..." will do? T.