Sha256: 68e36d7b2908a247098c4d9e27fa8ea2c95b5a9df49ceb654918334b17edf808
Contents?: true
Size: 882 Bytes
Versions: 2
Compression:
Stored size: 882 Bytes
Contents
module Polyfill module V2_6 module Array def difference(*arrays) arrays.reduce([*self]) do |me, array| me - array end end def to_h return super unless block_given? block = ::Proc.new pairs = map.with_index do |elem, i| pair = block.call(elem) unless pair.respond_to?(:to_ary) raise TypeError, "wrong element type #{pair.class} at #{i} (expected array)" end pair = pair.to_ary unless pair.length == 2 raise ArgumentError, "wrong array length at #{i} (expected 2, was #{pair.length})" end pair end pairs.to_h end def union(*arrays) return self | [] if arrays.empty? arrays.reduce(self) do |me, array| me | array end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
polyfill-1.9.0 | lib/polyfill/v2_6/array.rb |
polyfill-1.8.0 | lib/polyfill/v2_6/array.rb |