Hi --

On Thu, 11 Jul 2002, Tom Sawyer wrote:

> hmmm...
>
> don't really like the long name. alias iterate ?

I think it would be confusing not to see the familiar name.

> but then i wonder, is it possible to define iterators that recognize
> the number of parameters and act accordingly?
>
> # just the object
> arr.each  { |x|
>   ...
> }
>
> # the object with index
> arr.each |x, i| {
>  ...
> }

Array#each can't really work that way -- there are too many possible
calls that need the two arguments:

  [ [1,2], [3,4] ].each {|x,i| ... }  # etc.

but you could write an iterator that did (based on the block's arity,
maybe).  Then again, Enumerable gives you #each_with_index for free
:-)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav