---2049402039-1184309673-11645563881991 Content-Type: MULTIPART/MIXED; BOUNDARY="-2049402039-1184309673-1164556388=:11991" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---2049402039-1184309673-11645563881991 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Mon, 27 Nov 2006, James Edward Gray II wrote: > On Nov 26, 2006, at 8:54 AM, Olivier wrote: > >> Le dimanche 26 novembre 2006 15:00, Josselin a ñÄrit : >>> >>> array.index(array.detect {|x| x > 0}) => 15 >> >> c = 0 >> array.each{|v| break if not v.zero?; c += 1} >> puts c # => 15 > >>> result = array.enum_with_index.find { |n, i| n.nonzero? }.last rescueil That seems kind of like a reinvention of Array#index, though. It also has the usual problem with rescue, i.e., that you might rescue the wrong thing (if nonzero? is mistyped or whatever). Do you see an advantage to doing it this way, rather than the index/detect way? (I'm being lazy and not benchmarking them....) David -- David A. Black | dblack / wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org ---2049402039-1184309673-11645563881991-- ---2049402039-1184309673-11645563881991--