Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/with_validations/core_ext/hash.rb

Instance Method Summary (collapse)

Instance Method Details

- (Hash) delete_keys!(*keys)

Note:

keys in `*keys` not present in `self` are silently ignored.

Removes `*keys` from self.

Returns:

  • (Hash)

    self with `*keys` removed.



8
9
10
11
12
# File 'lib/with_validations/core_ext/hash.rb', line 8

def delete_keys!(*keys)
  keys.each do |key|
    self.delete(key)
  end
end

- (Hash) slice(*keys)

Note:

keys in `*keys` not present in `self` are silently ignored.

Creates a sub-hash from `self` with the keys from `*keys`.

Returns:

  • (Hash)

    a copy of `self`.



18
19
20
# File 'lib/with_validations/core_ext/hash.rb', line 18

def slice(*keys)
  self.select { |k,v| keys.include?(k) }
end