Sha256: 78e4cf727c63fedb1d63c76d00675e8f4c4325223a46a57c1a3533f5fcdfed29

Contents?: true

Size: 526 Bytes

Versions: 47

Compression:

Stored size: 526 Bytes

Contents

unless ([1].pop(1) rescue false)
  require 'backports/tools/alias_method_chain'
  require 'backports/tools/arguments'

  class Array
    def pop_with_optional_argument(n = Backports::Undefined)
      return pop_without_optional_argument if n == Backports::Undefined
      n = Backports.coerce_to_int(n)
      raise ArgumentError, "negative array size" if n < 0
      first = size - n
      first = 0 if first < 0
      slice!(first..size).to_a
    end
    Backports.alias_method_chain self, :pop, :optional_argument
  end
end

Version data entries

47 entries across 47 versions & 4 rubygems

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