Sha256: 53827573fb8facf331698c6cc71c06b4bdf30bbf39782f72dbccf6f36d325c3f

Contents?: true

Size: 534 Bytes

Versions: 9

Compression:

Stored size: 534 Bytes

Contents

module Polyfill
  module V2_5
    module Hash
      def slice(*keys)
        keys.each_with_object({}) do |k, acc|
          acc[k] = self[k] if key?(k)
        end
      end

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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
polyfill-1.9.0 lib/polyfill/v2_5/hash.rb
polyfill-1.8.0 lib/polyfill/v2_5/hash.rb
polyfill-1.7.0 lib/polyfill/v2_5/hash.rb
polyfill-1.6.0 lib/polyfill/v2_5/hash.rb
polyfill-1.5.0 lib/polyfill/v2_5/hash.rb
polyfill-1.4.0 lib/polyfill/v2_5/hash.rb
polyfill-1.3.0 lib/polyfill/v2_5/hash.rb
polyfill-1.2.0 lib/polyfill/v2_5/hash.rb
polyfill-1.1.0 lib/polyfill/v2_5/hash.rb