I have a hash of name / value pairs:
attr_hash = {"attr1"=>"val1","attr2=>"val2"}
I want to cycle through each one of these values and assign them to an object like so:
thing = Thing.new
attr_hash.each do |k,v|
thing.k = v
end
class Thing
attr_accessor :attr1, :attr2
end
The problem of course being that attr1 is and attr2 are strings.. So I can't do something like thing."attr1"
I've tried doing:
thing.send(k,v) but that doesn't work