Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a setter method via a symbol

if send is used for calling a method with a symbol (which for an attribute is the getter method)

what is the opposite for accessing the setter method?

object.send(:attr) is to object.attr

as

______ is to object.attr = value

sorry for the analogies, I don't know how to better explain this

like image 545
Nick Ginanto Avatar asked Jan 10 '23 01:01

Nick Ginanto


2 Answers

I assume you're trying to dynamically set the value of various attributes on an object.

try the following:

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

There was a similar question asked yesterday - it might help as it's a more specific example.

like image 200
dax Avatar answered Jan 19 '23 08:01

dax


Try using:

object.send(column + '=', column_value)
like image 20
Michael Durrant Avatar answered Jan 19 '23 10:01

Michael Durrant