Sha256: bf6662e145adaed3e52da07393d7b151cf9ecf5513c52bd94c71b3bc43c0147d

Contents?: true

Size: 542 Bytes

Versions: 8

Compression:

Stored size: 542 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

8 entries across 8 versions & 1 rubygems

Version Path
cape-1.6.0 lib/cape/core_ext/hash.rb
cape-1.5.0 lib/cape/core_ext/hash.rb
cape-1.4.0 lib/cape/core_ext/hash.rb
cape-1.3.0 lib/cape/core_ext/hash.rb
cape-1.2.0 lib/cape/core_ext/hash.rb
cape-1.1.0 lib/cape/core_ext/hash.rb
cape-1.0.3 lib/cape/core_ext/hash.rb
cape-1.0.2 lib/cape/core_ext/hash.rb