[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-core
Subject:    Re: method_missing for Enumerator
From:       Daniel DeLorme <dan-ml () dan42 ! com>
Date:       2007-06-25 23:42:15
Message-ID: 468052D4.30104 () dan42 ! com
[Download RAW message or body]

TRANS wrote:
> But I take your point, I had tried using a separate class
> (Enumerable::Elementor), but it meant using a #to_elem (eg.
> [1,2,3].to_elem(:select) > 2) which largely killed the effect. Unless
> someone has better ideas for achieving R-like operations, adding
> method_missing to Enumerator seems like the best bet. I'll make it as
> an add-on library of Facets.

Maybe making it more explicit would remove a lot of the perceived 
danger, e.g.:

   class Enumerable::Enumerator
     def for
       enum = self.dup
       def enum.method_missing...
       enum
     end
   end
   [1,2,3].select.for > 2

or alternatively:

   class Enumerable::Enumerator
     def element
       Enumerable::Elementor(self)
     end
   end
   [1,2,3].select.element > 2

I think that's getting awfully close to higher order messaging though.


Daniel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic