How can I set an object attribute dynamically in Ruby e.g.
def set_property(obj, prop_name, prop_value) #need to do something like > obj.prop_name =
This answer (https://stackoverflow.com/a/7466385/6094965) worked for me:
Object.send(attribute + '=', value)
attribute has to be a String. So if you are iterating trough an array of Symbols (like me), you can use to_s.
attribute
String
Symbol
to_s
Object.send(attribute.to_s + '=', value)