Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/drink-socially/extensions/hash.rb

Instance Method Summary collapse

Instance Method Details

#slice(*keys) ⇒ Object



3
4
5
6
7
# File 'lib/drink-socially/extensions/hash.rb', line 3

def slice(*keys)
  hash = self.class.new
  keys.each { |k| hash[k] = self[k] if has_key?(k) }
  hash
end

#slice!(*keys) ⇒ Object



10
11
12
13
14
15
# File 'lib/drink-socially/extensions/hash.rb', line 10

def slice!(*keys)
  omit = slice(*self.keys - keys)
  hash = slice(*keys)
  replace(hash)
  omit
end