max_by with block : max_by « Array « Ruby






max_by with block


langs = %w[java perl python ruby]    # Which has the longest name?
langs.max_by {|word| word.length }   # => "python": Ruby 1.9 only

 

Related examples in the same category