From: Devin Mullins Date: 2006-11-27T04:14:10+09:00 Subject: Re: find index of first non zeo value in array Robert Klemme wrote: > Did we have a solution with #inject already? In case we didn't: > > irb(main):001:0> require 'enumerator' > => true > irb(main):002:0> a=Array.new(10,0) << 666 << 0 > => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 666, 0] > irb(main):003:0> a.to_enum(:each_with_index).inject(nil) {|pp,(x,i)| > break i unless x == 0} > => 10 sub 'inject(nil) {|pp,(x,i)|', 'find {|x,i|' But I vote for adding to Enumerable or Array. #index_where or #find_by or something. (My preference over alias-and-delegate.) Devin