Enumerator#rest みたいなのが欲しい
Ruby の Enumerator で、列挙はひとつずつしかできない。まとめていくつか列挙できるメソッドが欲しい。
こんな感じ。
class Enumerator def rest(n=nil) ary = [] case n in nil loop { ary << self.next } in Integer => a a.times { ary << self.next } end ary end end a = [*1..10].to_enum a.next #=>1 a.next #=>2 a.rest(4) #=>[3, 4, 5, 6] a.next #=>7 a.rest #=>[8, 9, 10]
ダメですかねえ…。