module Enumerable
Extensions to the Enumerable
module
Public Instance Methods
max_with_index() { |obj| ... }
click to toggle source
Calculate a value for each item, and return the item with the highest value, its index, and the value. @yieldparam function to calculate value of an object, given that object as a parameter @return the triple [object, index, value] reflecting the maximum value, or
nil if there were no items
# File lib/tokn/tools.rb, line 160 def max_with_index best = nil each_with_index do |obj,ind| sc = yield(obj) if !best || best[2] < sc best = [obj,ind,sc] end end best end