On 7/17/07, Trans <transfire / gmail.com> wrote:
> Can anyone demonstrate problems with the following?
>
>   # Adds immediate elementwise ability to Enumerator.
>   # Any non-enumeration method is passed on to each.
>   #
>   #   [1,2,3].to_enum(:map) + 3
>   #   => [4,5,6]
>   #
>   # Note there may be a few essential methods this can not
>   # be used on, such as #object_id.
>
>   class Enumerable::Enumerator
>     def method_missing(sym,*args,&blk)
>       each{ |x| x.send(sym,*args,&blk) }
>     end
>   end
>
> I like the simplicity of this and would rather use it than add an
> another class layer, but I need to be sure I'm not overlooking any
> potential dangers with doing so.
>
Hmm I do it like this in Labrador, but on map directly and I add a
class overlay so that indeed things like #object_id can be dispatched

irb(main):002:0> require 'labrador/enum'
=> true
irb(main):003:0> [1,2,3].map.object_id
=> [3, 5, 7]
irb(main):004:0>

I would indeed be very interested in dangers of this, but my
announcement went unnoticed, quite normal given the undocumented and
unstructured state of Labrador -- I work less than 1h/w for it :(.

I really do not like -- or know -- this to_enum stuff, it seems way to
verbose for me.
Attention I am not going to influence the community I just want to
find some fellow soul who likes my style. (Notably Magic Dot)

Sorry if I am hijacking a little bit, just say a word and I'll go away...

Robert
-- 
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck