Sha256: 2569e68eb660e69fecee07cbce2a9517dc665faf61cc72f5870b23f253bf790a
Contents?: true
Size: 567 Bytes
Versions: 26
Compression:
Stored size: 567 Bytes
Contents
unless Enumerable.method_defined? :minmax require 'backports/tools' 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
26 entries across 26 versions & 2 rubygems