[ruby-talk:02450] Re: Iterator into array

From: Dave Thomas <Dave@...>
Date: 2000-04-11 16:08:41 UTC
List: ruby-talk #2450
matz@netlab.co.jp (Yukihiro Matsumoto) writes:

> Hi,
> 
> In message "[ruby-talk:02444] Re: Iterator into array"
>     on 00/04/11, "Conrad Schneiker" <schneiker@jump.net> writes:
> 
> |So I think it would be good thing for Ruby if we could find some suitable
> |syntax extension "for collecting yielded values".
> 
> Although I agree with Conrad about feature-rich, Dave's "collecting
> yielded values" is not that simple unfortunately.  "collecting yielded
> values" works fine only for "iterators", but not applicable to all
> method with block in genreral.

This is another dumb idea, but... 

Say we allowed the syntax

    method1(args)  method2(args)

method2 would have to return a proc object.

Then we could do something like


  def into(anArray)
    proc { |i| anArray << i }
  end


  (1..10).each into(a = [])

Ideally I'd like the whole expression to return the array, but I can't 
see a tidy way to do that.


Dave

In This Thread