Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/roda/component.rb,
lib/roda/component/events.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge(second) ⇒ Object



4
5
6
7
# File 'lib/roda/component/events.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

#to_objObject

add keys to hash



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/roda/component.rb', line 87

def to_obj
  self.each do |k,v|
    if v.kind_of? Hash
      v.to_obj
    end
    k=k.to_s.gsub(/\.|\s|-|\/|\'/, '_').downcase.to_sym

    ## create and initialize an instance variable for this key/value pair
    self.instance_variable_set("@#{k}", v)

    ## create the getter that returns the instance variable
    self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")})

    ## create the setter that sets the instance variable
    self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)})
  end
  return self
end