From: "Berger, Daniel" Date: 2006-04-20T03:49:43+09:00 Subject: Re: Symbol#to_proc is just so beautiful > -----Original Message----- > From: Daniel Schierbeck [mailto:daniel.schierbeck@gmail.com] > Sent: Wednesday, April 19, 2006 12:41 PM > To: ruby-talk ML > Subject: Re: Symbol#to_proc is just so beautiful > > > 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) I don't like it. It bugs me. That ampersand is an eye sore in otherwise elegant syntax. I also worry about the inevitable, "Does that mean it's a reference?" questions this syntax will generate from newbies. Maybe, instead of changing Ruby to simplify Enumerable/Array/Hash methods (and let's face it, that's about 95% of the reason most people want this change) we should just, you know, change the Enumerable/Array/Hash API to accept symbolic methods for simple comparisons. Just my .02. Regards, Dan