1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-06 06:28:33 +00:00

Fixed matchup object to hash and hash to object

This commit is contained in:
2015-03-25 12:56:19 +00:00
parent e0f6c129c7
commit 06a4d1b95d
2 changed files with 25 additions and 22 deletions

View File

@@ -5,5 +5,20 @@ class Matchup
@weight = Weight.find(self.weight_id)
return @weight.max
end
def to_hash
hash = {}
instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
hash
end
def convert_to_obj(h)
h.each do |k,v|
self.class.send(:attr_accessor, k)
instance_variable_set("@#{k}", v)
convert_to_obj(v) if v.is_a? Hash
end
end
end