From: David Masover Date: 2011-06-07T23:54:08+09:00 Subject: Re: CORE - Altering Behaviour of "each do" (default param "item") On Tuesday, June 07, 2011 06:26:32 AM Adam Prescott wrote: > 2011/6/7 Jörg W Mittag > > > Ilias Lazaridis wrote: > > > I've just noticed repetitions within code like that: > > > > > > names.each { |name| puts name} # 3 times "name(s)" > > > > That's because nobody who knows even the tiniest bit of Ruby would > > ever write it like that. > > > > names.each(&method(:puts)) > > > > Would probably be the most idiomatic way. > > That's a fairly sweeping statement. I know more than the tiniest bit of > Ruby and I prefer { |name| puts name } to &method(:puts). More than > prefer, in fact, I would never use the latter. While I would use &method(:puts), it honestly never occurred to me, and it seems like a clever hack. It also only solves that one problem, and not, say: names.map{|name| name.split.last} I suppose I could do this instead, but it doesn't save any typing and results in an extra intermediate array being constructed: names.map(&:split).map(&:last) I'm sure I'm missing something, though.