Le dimanche 26 novembre 2006 15:00, Josselin a ˝─rit
> with :
> 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]
>
> I wrote :
> array.index(array.detect {|x| x > 0})    => 15
>
> is there a better and simpler way to do it ?
> thanks
>
> joss

In that case, it is simpler to use an external counter, i think :

c = 0
array.each{|v| break if not v.zero?; c += 1}
puts c # => 15