Module: Cape::CoreExt::Hash Private

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

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Adds methods missing from Ruby’s Hash core class.

Instance Method Summary collapse

Instance Method Details

#slice(*keys) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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