Sha256: b8a2139210f098bb541d23043b6485985098e3ca49413b9aa56512adad9437ce
Contents?: true
Size: 467 Bytes
Versions: 1
Compression:
Stored size: 467 Bytes
Contents
unless Enumerable.method_defined? :drop_last module Enumerable # Drops the last n elements of an enumerable. # # @return [Array] an array containing the remaining elements # # @example # [1, 2, 3].drop_last(1) #=> [1, 2] # [].drop_last(5) #=> [] def drop_last(n) fail ArgumentError, 'attempt to drop negative size' if n < 0 ary = to_a return [] if n > ary.size ary[0...(ary.size - n)] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
powerpack-0.0.6 | lib/powerpack/enumerable/drop_last.rb |