Check Global method exist inside a class method

Hi all,
I have a problem in identifying whether a global method exist or not,
from inside class, My code is similar to,

def myMethod
“my Method is executed\n”
end

class MyClass
def instMethod
if(respond_to?(“myMethod”))
myMethod
else
p “myMethod not found\n”
end
end
end

me = MyClass.new
me.instMethod

Here “respond_to?(“myMethod”)” fails, It seems to be only checking the
methods inside the class, not global methods.

So I like to know is there anyway to do this?

Thanks
Dimuthu

On 19 Nov 2007, at 09:20, Dimuthu wrote:

Here “respond_to?(“myMethod”)” fails, It seems to be only checking the
methods inside the class, not global methods.

top levels methods like that aren’t ‘global’ methods, they end up as
private methods on Object.

Fred

Hi Frederick,

Did you mean I should check with, Object.respond_to?(“myMethod”). But
It still it didnt’ work. Is that the Object you mention is not what I
mean here?
Can you please explain it little bit more?

Thanks
Dimuthu

On Nov 19, 3:08 pm, Frederick C. [email protected]

On 19 Nov 2007, at 14:31, Dimuthu wrote:

Hi Frederick,

Did you mean I should check with, Object.respond_to?(“myMethod”). But
It still it didnt’ work. Is that the Object you mention is not what I
mean here?
Can you please explain it little bit more?

by default, respond_to doesn’t check for private methods, but you can
force it : Object.respond_to?(:myMethod, true)

Fred

Thanks, It works

Dimuthu

On Nov 19, 8:00 pm, Frederick C. [email protected]