On 04.02.2008 17:46, Phlip wrote: > The winner is ActiveSupport's Array#in_groups_of (calling each_slice). > > Thanks y'all! > > But it only won for one reason - I need the array-of-twos so I can then > immediately call .each on it. in_groups_of already requires a block (and > does not return the twizzled array!), so I can just use it without the > each. So I would have called it each_group, but that didn't seem to > catch on... > > Here's why I need it. Ruby's opcodes express Hashes as strictly > even-lengthed arrays, going [key1, value1, key2, value2, etc]. So I just > needed to iterate those things in pairs, without excessive moduli to > detect if the current item is a key or a value. "Excessive moduli"? irb(main):003:0> %w{foo bar}.each_with_index {|e,i| puts "key #{e}" if i % 2 == 0} key foo => ["foo", "bar"] irb(main):004:0> %w{foo bar}.each_with_index {|e,i| puts "key #{e}" if i & 1 == 0} key foo => ["foo", "bar"] Cheers robert