Enumerators concatenation possible?

Hi,

just curious if it’s possible to concatenate two instances of Enumerator
class. For example

irb(main):001:0> e1 = 0.upto(3)
=> #<Enumerator: 0:upto(3)>
irb(main):002:0> e2 = 4.step(10**6,3)
=> #<Enumerator: 4:step(1000000, 3)>
irb(main):003:0> (e1 + e2).each {|i| … do some stuff … }

throws NoMethodError because ‘+’ is not defined for Enumerators

I’m looking for some way/trick how to join e1 with e2 without expanding
them to Arrays or writing own ‘concat’ method implementation.

Thanks.

David U. wrote in post #1006253:

just curious if it’s possible to concatenate two instances of Enumerator
class.

No, but it has been suggested (and rejected) here:

which also gives you an implementation you can use.