Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/conductor/util/hash.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge(second) ⇒ Object



4
5
6
7
# File 'lib/vagrant/conductor/util/hash.rb', line 4

def deep_merge(second)
  merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
  self.merge(second, &merger)
end

#find?(key, default = nil) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
# File 'lib/vagrant/conductor/util/hash.rb', line 9

def find?(key, default=nil)
  keys = key.split('.')
  if keys.length > 1
    key = keys.shift
    self.has_key?(key) ? self[key].find?(keys.join('.'), default) : default
  else
    self[key] || default
  end
end