From: Peter Vandenabeele Date: 2012-02-04T02:55:38+09:00 Subject: Re: Help please Undefined Method error --002354470c5c1fcb0104b81305b3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, Feb 3, 2012 at 6:46 PM, Bartosz Dziewo=C5=84ski wrote: > 2012/2/3 Peter Vandenabeele : > > > > def get_words > > [].tap do |a| > > while !(input =3D gets.chomp).empty? > > a << input > > end > > end > > end > > Aw. Do not abuse #tap, please. It's extremely unreadable, especially > to a beginner. > Thanks for the feedback. I find it quite readable, because it take the recipient (an empty array here), "augments" it, and then just returns it back. At least for me, I love it, because otherwise there is always a chance I forget the (return) as last line of the function. But, my argument is subjective ... > > * Use [].tap{|a| a<< stuff} so you do not have to return the > > result array explicitly (I am not having a variable "words" > > or "array" in the function, it is returned as the final result but > > not stored in an explicit local variable; so I can impossibly > > forget to return the built up array at the end, because "tap" > > returns it automatically > > There is no advantage to using constructs with tap over regular > variable I know of. IMO #tap should only be used to "inject" debugging > or other side-effects into a long method chain. (Although, if you have > a method chain so long, you probably have other problems...) > Could you kindly provide a clearer alternative for this functionality then? Interested, Peter --002354470c5c1fcb0104b81305b3--