Hello my problem is simple I have code which simplified looks like this
foo = OpenStruct.new
bar = OpenStruct.new
mappings.each do |k,v|
eval "foo.#{k} = bar.#{v}"
end
I am trying to fix this eval use and not use it 🙂 Figured out the right part but I do not know how to assign to left one. To access getter you could write.
bar.send(v.to_sym)
# not to sure how to access setter for foo
I am using Ruby 1.8.7, Thank you
Not sure about 1.8.7, but in newer Rubies this works:
Also, in newer versions,
sendaccepts strings as well, so you can omit.to_sym.