Module: Enumerable
- Defined in:
- lib/geotree/tools.rb
Overview
Extensions to the Enumerable module
Instance Method Summary collapse
-
#max_with_index {|function| ... } ⇒ Object
Calculate a value for each item, and return the item with the highest value, its index, and the value.
Instance Method Details
#max_with_index {|function| ... } ⇒ Object
Calculate a value for each item, and return the item with the highest value, its index, and the value.
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/geotree/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 |