Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/manifestly/utilities.rb

Instance Method Summary collapse

Instance Method Details

#except(*keys) ⇒ Object



11
12
13
# File 'lib/manifestly/utilities.rb', line 11

def except(*keys)
  dup.except!(*keys)
end

#except!(*keys) ⇒ Object



6
7
8
9
# File 'lib/manifestly/utilities.rb', line 6

def except!(*keys)
  keys.each { |key| delete(key) }
  self
end

#get_deep(*fields) ⇒ Object



2
3
4
# File 'lib/manifestly/utilities.rb', line 2

def get_deep(*fields)
  fields.inject(self) {|acc,e| acc[e] if acc}
end

#slice(*keys) ⇒ Object



15
16
17
18
# File 'lib/manifestly/utilities.rb', line 15

def slice(*keys)
  keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
  keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if has_key?(k) }
end