1.9 での each の返り値

p [1, 2, 3].combination(2).each {}       #=> [1, 2, 3]
p [1, 2, 3].combination(2).to_a.each {}  #=> [[1, 2], [1, 3], [2, 3]]

なんだか微妙。上の例は combination(2) の返り値 (Enumerator) を返してくれたほうが直感に合う気も。

p [1, 2, 3].combination(2).each_with_index {}
#=> #<Enumerable::Enumerator:0xb7cee3b8>
p [1, 2, 3].combination(2).each_with_index {}.to_a
#=> [[1, 2], [1, 3], [2, 3]]
p [1, 2, 3].combination(2).to_a.each_with_index {}
#=> [[1, 2], [1, 3], [2, 3]]

そうそうこんな感じ。
でも each 系メソッドの返り値を使うことなんて滅多になさそうだから、いっそすべて nil を返すようにしてしまえば清々しい気もする。


いずれにしても、1.9 の generator 周りはこなれてない印象が強いです。単に僕が慣れてないだけかな。