Let's say I have a class
class MyClass
def sayMyName()
puts "I am unknown"
end
end
and I have stored this method name in a variable: methodName = "saymyName"
I want to call this method by using above variable, something like this:
instance = MyClass.new
instance[methodName]
I know it can be called using a macro but I don't get how? Please someone provide an example with explanation.
Update 1
There is already an answer for this: Calling methods dynamically (Crystal-lang) but this doesn't answer how to do it when methods are inside a class.