On 6/24/07, Trans <transfire / gmail.com> wrote: > Well, I might as well bring up the reason I asked about enum_obj... > > Spending some time improving Facets' Elementor class concept and > #every method, I find this possible utter simplification: > > class Enumerable::Enumerator > def method_missing(sym, *args, &blk) > self.class.new(collect{ |e| e.send(sym, *args, &blk) }) > end > end > > Example: > > a = [1,2,3] > e = a.to_enum > e += 3 > e *= 2 > e.to_a #=> [8,10,11] > > T. Apart the magic dot notation that is *exactly* what I am doing in Labrador. Well I cannot expect blocks in this way as they have the original purpose and are sent to map. module Enumerable alias_method :__map_l1, :map # # The behavior of map {...} is unchanged. # map(arg1, *rest) simply is translated to map{ |ele| ele.send(arg1, *rest) } # map(arg1, *rest){...} is translated to map{|ele| ele.send(arg1,*rest}.map{...} # map without any arguments creates a Dispatcher Proxy that will dispatch all messages # to the elements of the receiver. # # All the following expressions evaluate therefore to the same result: # ary=[*0..9] # ary.map{ |x| x + 1} # ary.map(:succ) # ary.map.succ # ary.map(:+, 1) # ary.map + 1 def map *args, &blk return Labrador::Dispatcher.new( self, :map ) if args.empty? && blk.nil? return __map_l1( &blk ) if args.empty? return __map_l1 { |x| x.send( *args ) } if blk.nil? __map_l1 { |x| x.send( *args ) }.__map_l1( &blk ) end # def map *args, &blk end # module Enumerable Robert -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw