if ...
o = User
elseif ...
o = Car
o.send(:count) = 100
o.send(:is_high) = true
o.save!
I want to reduce the duplicate code, is this ok to do?
I will have tests for this in case property names change etc.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Doing
o.send(:count) = 100will give you a syntax error so presumably you really mean this:Yes, that’s fine but will leave the people maintaining your code scratching their heads and wondering why didn’t just do this:
You usually only use
sendwhen you don’t know the method name until run time: