method_defined? doesn't see module methods?

M

matt neuburg

module M
def self.howdy
"hello"
end
end
p M.method_defined? :howdy #=> false

What question should I ask in order to get "true"? Thx - m.
 
S

Stefano Crocco

Alle Sunday 27 January 2008, matt neuburg ha scritto:
module M
def self.howdy
"hello"
end
end
p M.method_defined? :howdy #=> false

What question should I ask in order to get "true"? Thx - m.

According to the ri documentation, method_defined? tells wether instances of
the class, or of a class including the module, will respond to the given
method. In other words :

Cls.method_defined?:)a_method) == true

means that

Cls.new.respond_to?:)a_method) == true

To know whether the module has a module method, you can use respond_to? on the
module:

M.respond_to?:)howdy)
=> true

I hope this helps

Stefano
 
M

matt neuburg

Stefano Crocco said:
Alle Sunday 27 January 2008, matt neuburg ha scritto:

To know whether the module has a module method, you can use respond_to? on the
module:

M.respond_to?:)howdy)
=> true

Excellent, thanks! m.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top