From: Devin Mullins Date: 2006-11-27T01:29:43+09:00 Subject: Re: find index of first non zeo value in array James Edward Gray II wrote: > I believe there has been talk in the past of having index() take a > block for matching. Meh... talk schmalk... class Array alias orig_index index def index(*args) return orig_index(*args) unless block_given? (0...length).each do |i| return i if yield self[i] end nil end end array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] array.index 21 #=> 15 array.index {|n| n.nonzero? } #=> 15 Devin