RCR: Accumulating block

A bit of a wild idea, but how about syntactic support for accumulating
the results of multiple calls to yield?

a = []
(1…10).step(2) {|i|

a << retval
}

could become

a = (1…10).step(2) [|i| …]

martin

Hi,

At Sun, 25 Apr 2004 03:04:04 +0900,
Martin DeMello wrote in [ruby-talk:98258]:

A bit of a wild idea, but how about syntactic support for accumulating
the results of multiple calls to yield?

a =
(1…10).step(2) {|i|

a << retval
}

could become

a = (1…10).step(2) [|i| …]

I don’t feel it so essential.

$ ruby -renumerator -e 'p (1…10).enum_for(:step, 2).to_a
[1, 3, 5, 7, 9]

···


Nobu Nakada

Ah yes, I forgot about enum_for.

martin

···

nobu.nokada@softhome.net wrote:

Martin DeMello wrote in [ruby-talk:98258]:

a = (1…10).step(2) [|i| …]

I don’t feel it so essential.

$ ruby -renumerator -e 'p (1…10).enum_for(:step, 2).to_a
[1, 3, 5, 7, 9]