> No, this does not work reliably (e.g. when there are only negative
> numbers in array).

Okay, then:

    Array.max_by{|x| x < limit ? x : nil }


Nothing wrong with max_by AFAIK.

None of my example code posted here is fully tested against all possible data sets.  I'm sorry if you assumed it was.


Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer>

Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>