From: FireAphis Date: 2007-08-09T13:34:58+09:00 Subject: Re: Iterating list in pairs On Aug 8, 5:35 pm, "Robert Dober" wrote: > On 8/8/07, dbl...@rubypal.com wrote:> Hi -- > > > On Wed, 8 Aug 2007, Robert Dober wrote: > > > > require 'labrador/enum' > > > a.zip(a.map.succ).map.join.first(-1) > > map without a parameter creates a Proxy object that contains the > enumeration and the method name :map. > It's method_missing forwards everything to the enumeration via send > and the method name, thus > map.join becomes > map{|x| x.send(:join)} > > it is not everybody's cup of tea, but I love it, obviously. > Labrador, the LAZY programmers best friend ;) > > class EmptyProxy < EmptyObject > def initialize object, message > @enum = object > @message = message > end > end > > class Dispatcher < EmptyProxy > def method_missing mth, *args, &blk > @enum.send(@message){|x| x.send(mth.to_sym,*args)} > end # def method_missing mth, *args, &blk > end # class Dispatcher < EmptyProxy > > Cheers > Robert > > -- > [...] as simple as possible, but no simpler. > -- Attributed to Albert Einstein Thanks everybody for help and plethora of solution ideas you've been very helpful. Thanks again FireAphis