On Dec 14, 8:28 am, Jari Williamsson <jari.williams... / mailbox.swipnet.se> wrote: > I'm going through lots of data where the result of the current is > affected by the previous element. So what I would need is an > "each_with_previous {|current, prev|}" > ..to make it a bit more readable. Is there any built-in Ruby method > that I might have overlooked, or should I build my own? Take your pick: irb(main):001:0> a = %w| a b c d e f g h | => ["a", "b", "c", "d", "e", "f", "g", "h"] irb(main):002:0> require 'enumerator' irb(main):003:0> a.each_cons(2){ |x,y| puts "#{x}-#{y}" } a-b b-c c-d d-e e-f f-g g-h irb(main):004:0> a.each_slice(2){ |x,y| puts "#{x}-#{y}" } a-b c-d e-f g-h