Sha256: d7423c03ee5dfeabc23edf6caf7877f8664dca5d55c6b778b35a3e635ac64cc7
Contents?: true
Size: 577 Bytes
Versions: 47
Compression:
Stored size: 577 Bytes
Contents
unless Enumerable.method_defined? :minmax require 'backports/tools/arguments' module Enumerable def minmax return minmax{|a,b| a <=> b} unless block_given? first_time = true min, max = nil each do |object| if first_time min = max = object first_time = false else min = object if Backports.coerce_to_comparison(min, object, yield(min, object)) > 0 max = object if Backports.coerce_to_comparison(max, object, yield(max, object)) < 0 end end [min, max] end end end
Version data entries
47 entries across 47 versions & 4 rubygems