Class: Hashit

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly_extensions/monkey_patches.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Hashit

Returns a new instance of Hashit.



28
29
30
31
32
33
34
# File 'lib/dragonfly_extensions/monkey_patches.rb', line 28

def initialize(hash)
  hash.each do |k,v|
    self.instance_variable_set("@#{k}", v)
    self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")})
    self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)})
  end
end

Instance Method Details

#saveObject



36
37
38
39
40
41
42
# File 'lib/dragonfly_extensions/monkey_patches.rb', line 36

def save
  hash_to_return = {}
  self.instance_variables.each do |var|
    hash_to_return[var.gsub("@","")] = self.instance_variable_get(var)
  end
  return hash_to_return
end