Sha256: 90b919406a2f0535af205e44ebb114734573dbb85d608c2beee2a0d84d72a25d

Contents?: true

Size: 894 Bytes

Versions: 15

Compression:

Stored size: 894 Bytes

Contents

module Polyfill
  module V2_4
    module Hash
      def compact
        reject { |_, v| v.nil? }
      end

      def compact!
        reject! { |_, v| v.nil? }
      end

      def transform_values
        unless block_given?
          return ::Enumerator.new(keys.size) do |yielder|
            each_with_object({}) do |(k, v), acc|
              acc[k] = yielder.yield(v)
            end
          end
        end

        each_with_object({}) do |(k, v), acc|
          acc[k] = yield(v)
        end
      end

      def transform_values!
        unless block_given?
          return ::Enumerator.new(keys.size) do |yielder|
            replace(each_with_object({}) do |(k, v), acc|
              acc[k] = yielder.yield(v)
            end)
          end
        end

        replace(each_with_object({}) do |(k, v), acc|
          acc[k] = yield(v)
        end)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
polyfill-1.9.0 lib/polyfill/v2_4/hash.rb
polyfill-1.8.0 lib/polyfill/v2_4/hash.rb
polyfill-1.7.0 lib/polyfill/v2_4/hash.rb
polyfill-1.6.0 lib/polyfill/v2_4/hash.rb
polyfill-1.5.0 lib/polyfill/v2_4/hash.rb
polyfill-1.4.0 lib/polyfill/v2_4/hash.rb
polyfill-1.3.0 lib/polyfill/v2_4/hash.rb
polyfill-1.2.0 lib/polyfill/v2_4/hash.rb
polyfill-1.1.0 lib/polyfill/v2_4/hash.rb
polyfill-1.0.1 lib/polyfill/v2_4/hash.rb
polyfill-1.0.0 lib/polyfill/v2_4/hash.rb
polyfill-0.10.0 lib/polyfill/v2_4/hash.rb
polyfill-0.9.0 lib/polyfill/v2_4/hash.rb
polyfill-0.8.0 lib/polyfill/v2_4/hash.rb
polyfill-0.7.0 lib/polyfill/v2_4/hash.rb