I would like to maintain my code DRY, then I want to transform this pseudo-code:
def aMethod
a = aModel.find(2)
b = a.getVariable
a.setVariable = c
end
in something like this
def aMethod
anotherMethod(aModel, getVariable)
end
def anotherMethod(model, var)
a = model.find(2)
b = a.var
a.var = c
end
In my tests, seems that there is no problem for the model, but for the getVariable (i.e. accessing the variable of the model) it doesn’t work: undefined local variable or method
Any ideas?
You likely want to use
send, if I understand what you’re trying to do, e.g.,(With the caveat that I don’t know what
a,b, orcare, or should do, since they’re locals in the OP.)