Ruby Question: Is there a way to call a method like a selector in Objective-C

In Obj-C, the invocation method can be determined at runtime using a selector.

Is there something similar in Ruby so that I can convert a method string to a method character at runtime and call it?

+4
source share
2 answers

You need a send method:

obj.send(method_name) , where method_name can be either a string or a character, will call the method with the given name in obj .

Any arguments that you want to pass to the method can be specified as additional arguments for send , i.e. obj.send(method_name, argument1, argument2) .

+3
source
0
source

All Articles