Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/nub/core.rb,
lib/nub/hash.rb

Overview

Monkey patch string with some useful methods

Instance Method Summary collapse

Instance Method Details

#cloneObject

Do a deep copy on the object



108
109
110
111
112
# File 'lib/nub/core.rb', line 108

def clone
  hash = {}
  self.each{|k, v| hash[k] = v.clone }
  return hash
end

#deep_merge(other) ⇒ Object

Deep merge hash with other

Parameters:

  • other (Hash)

    other hash to merge with



27
28
29
30
31
32
33
34
35
# File 'lib/nub/hash.rb', line 27

def deep_merge(other)
  merge(other){|k, av, bv|
    if av.is_a?(Hash) && bv.is_a?(Hash)
      av.deep_merge(bv)
    else
      bv
    end
  }
end

#deep_merge!(other) ⇒ Object

Deep merge hash with other

Parameters:

  • other (Hash)

    other hash to merge with



39
40
41
42
43
44
45
46
47
# File 'lib/nub/hash.rb', line 39

def deep_merge!(other)
  merge!(other){|k, av, bv|
    if av.is_a?(Hash) && bv.is_a?(Hash)
      av.deep_merge!(bv)
    else
      bv
    end
  }
end

#erb(vars = {}) ⇒ Object

Easily inject ERB variables into hash values

vars

hash of variables to inject into the string



116
117
118
# File 'lib/nub/core.rb', line 116

def erb(vars = {})
  ERBResolve.new(vars).resolve(self)
end

#erb!(vars = {}) ⇒ Object

Easily inject ERB variables into hash values

vars

hash of variables to inject into the string



122
123
124
# File 'lib/nub/core.rb', line 122

def erb!(vars = {})
  ERBResolve.new(vars).resolve!(self)
end