F
Fredrik
I have a method by the name methodA. I want to access this method like
this
a = 'methodA'
eval(a)
But how do I know if the variable a actually holds the name of a
defined method? An exception is raised if I try to run eval(a) with an
incorrect method name, but I need to know this before I call eval(a).
How do I do that?
I found this solution:
def method?(arg)
begin
method(a)
rescue
nil
end
end
which does work, but why is this function "method?" not already in the
Ruby language then?
this
a = 'methodA'
eval(a)
But how do I know if the variable a actually holds the name of a
defined method? An exception is raised if I try to run eval(a) with an
incorrect method name, but I need to know this before I call eval(a).
How do I do that?
I found this solution:
def method?(arg)
begin
method(a)
rescue
nil
end
end
which does work, but why is this function "method?" not already in the
Ruby language then?