From: Adam Prescott Date: 2010-10-07T02:47:10+09:00 Subject: Re: The beauty of Ruby through examples I don't see this as much of a good use of inject, to be honest. I'd rather see this: numbers = [1, 2, 3, 4, 6, 7, 8, 9] numbers.each_cons(2) { |x, y| break x if x.succ != y } or to get rid of the need to explain how break works and what succ is, while allowing more readability, perhaps numbers = [1, 2, 3, 4, 6, 7, 9, 10] # has a gap after 4 and 7! gaps = [] numbers.each_cons(2) do |x, y| gaps << x unless y == x + 1 end gaps #=> [4, 7] You'll possibly have to explain each_cons, but I think it's easier than explaining inject to someone who doesn't know Ruby or programming. You also get to show off post-statement "unless"! On Wed, Oct 6, 2010 at 3:04 PM, Giampiero Zanchi wrote: > find the first gap in array of fixnum values > > p [1,2,3,5,6,8,9,10].inject {|a, e| e == a.next ? e : (break a.next)} > > will produce 4 > -- > Posted via http://www.ruby-forum.com/. > >