Module: Cape::CoreExt::Hash

Defined in:
lib/cape/core_ext/hash.rb

Overview

Adds methods missing from Ruby’s Hash core class.

Instance Method Summary collapse

Instance Method Details

#slice(*keys) ⇒ Hash

Returns a copy of the Hash containing values only for the specified keys.

Parameters:

  • keys (Array)

    zero or more hash keys

Returns:

  • (Hash)

    a subset of the Hash



14
15
16
# File 'lib/cape/core_ext/hash.rb', line 14

def slice(*keys)
  ::Hash[select { |key, value| keys.include? key }]
end