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

Version Path
backports-3.25.0 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.24.1 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.24.0 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.23.0 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.22.1 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.22.0 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.21.0 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.20.2 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.20.1 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.20.0 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.19.0 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.18.2 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.18.1 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.18.0 lib/backports/1.8.7/enumerable/minmax.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/backports-3.12.0/lib/backports/1.8.7/enumerable/minmax.rb
backports-3.17.2 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.17.1 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.17.0 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.16.1 lib/backports/1.8.7/enumerable/minmax.rb
backports-3.16.0 lib/backports/1.8.7/enumerable/minmax.rb