From: "Gerardo Santana Gómez Garrido" Date: 2006-04-20T04:13:19+09:00 Subject: Re: Symbol#to_proc is just so beautiful 2006/4/19, Daniel Schierbeck : > Berger, Daniel wrote: > >> [1, 2, 3].all? &:positive? => true > >> [-1, 2, 3].all? &:positive? => false > > There must be a way to ditch that '&' somehow. I'd prefer this: > > [1,2,3].all?(:positive?) > > The beauty of Symbol#to_proc is that you don't need to change any method > definitions for it to work; any method that yields a single argument can > take a symbol proc as a block, and it'll work out of the box. > > arr.any? &:positive? > arr.none? &:positive? > arr.each(&:upcase!) > arr.collect(&:downcase) An approach similar to Facets' Enumerable#every would look better arry.any?.positive? arr.none?.positive? arr.each.upcase! arry.collect.downcase # arry.every.downcase But it would require modification of all those methods, like Jacob says. It is worthwhile, in my opinion. -- Gerardo Santana "Between individuals, as between nations, respect for the rights of others is peace" - Don Benito Ju�rez http://santanatechnotes.blogspot.com/