Calling a setter method using a symbol

if send

used to call a method with a symbol (which for an attribute is a getter method)

what is the inverse for accessing the setter method?

object.send(:attr)

corresponds object.attr

and

______ -object.attr = value

Sorry for the analogy, I don't know how best to explain this.

+3


source to share


2 answers


I am assuming you are trying to dynamically set the value of various attributes on an object.

try this:



object.send("#{attr}=", value)

      

There was a similar question yesterday that might help as this is a more specific example.

+6


source


Try using:



object.send(column + '=', column_value)

      

+1


source







All Articles