Sha256: 0f47268c5ef9c94435d6355bb95482dc62e92d8715f6d8686fe267dbc35ec5c2

Contents?: true

Size: 550 Bytes

Versions: 4

Compression:

Stored size: 550 Bytes

Contents

module Cape

  module CoreExt

    # Adds methods missing from Ruby's Hash core class.
    module Hash

      # Returns a copy of the Hash containing values only for the specified
      # _keys_.
      #
      # @param [Array] keys zero or more hash keys
      #
      # @return [Hash] a subset of the Hash
      def slice(*keys)
        ::Hash[select { |key, value| keys.include? key }]
      end

    end

  end

end

unless ::Hash.instance_methods.collect(&:to_s).include?('slice')
  ::Hash.class_eval do
    include Cape::CoreExt::Hash
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cape-1.8.0 lib/cape/core_ext/hash.rb
cape-1.7.0 lib/cape/core_ext/hash.rb
cape-1.6.2 lib/cape/core_ext/hash.rb
cape-1.6.1 lib/cape/core_ext/hash.rb