How to use a parameter value as a variable name of an instance of an object?
This is an object.
Class MyClass
def initialize(ex,ey)
@myvar = ex
@myothervar = ey
end
end
I have the following method
def test(element)
instanceofMyClass.element
end
How can I get a test method that returns the value myvar or myothervar depending on the element parameter. I do not want to write an if condition, although I want to pass myvar or myother var through an element to an object instance, if possible.
source
share