On May 21, 6:41 am, "Erwin Abbott" <erwin.abb... / gmail.com> wrote:
> Hi
>
> I've written a number of classes which would benefit from the
> Enumerable mixin, but my #each method requires arguments.  These are
> usually to specify the range of values, like Fibonacci#each(first,
> last) or whatever.  Since Enumerable's #map, #collect, etc don't take
> arguments, how should I proceed?  I would be okay with wrapping the
> Enumerable methods I need, but that doesn't seem possible.  Do I just
> have to implement my own #map, #to_a, etc?

The standard response is "use enumerator and to_enum". but if you feel
like me, that's equivalent to tying knots in your spaghetti noodles to
save money on rotini.

I heard rumor that a future Ruby will ultimately pass thru each
parameters, but in the mean time you can have a go with Facets
enumerablepass.rb (http://facets.rubyforge.org).

An alternative is to use a functor (a function delegator) for your
parameters, eg.

  f = Foo.new
  f.range(1,5).each{|x| p x}

T.