I am trying to write a ruby function that iterates through an array of strings that are method names and uses the Object#send method to save values in a new instance object (not even sure if thats legit) that is a transformation of an already existing one. That’s the best I can explain it. Here’s the idea:
@example = RelatedClass.new
def example_method
instance_dependant_float = related_class.myvalue / other_related_class.myvalue
ARRAY_OF_METHODS.each do |t|
@example.send(t+'=', self.related_class.t * instance_dependant_float)
end
end
When I try to run something like this where I call the index “t” on two separate ocassions (in my send and in the multiplier) it NoMethodError’s on the second ocassion.
You need to
sendto get the value also:I always use and advocate string interpolation over
String#+, and you don’t need theself.to get therelated_class.