Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/rubocop/core_ext/hash.rb
Overview
Extensions to the core Hash class
Instance Method Summary collapse
-
#slice(*keys) ⇒ Hash
Adds ‘Hash#slice` for Ruby 2.4.
Instance Method Details
#slice(*keys) ⇒ Hash
Adds ‘Hash#slice` for Ruby 2.4. Returns a hash containing a subset of keys. If a given key is not in the hash, it will not be returned.
14 15 16 17 18 |
# File 'lib/rubocop/core_ext/hash.rb', line 14 def slice(*keys) h = {} keys.each { |k| h[k] = self[k] if key?(k) } h end |