# Method\_defined? doesn't see module methods?

**URL:** <https://www.ruby-forum.com/t/method-defined-doesnt-see-module-methods/127282>\
**Category:** Ruby\
**Created:** [January 27, 2008, 6:47pm UTC](https://www.ruby-forum.com/t/method-defined-doesnt-see-module-methods/127282 "2008-01-27T18:47:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt\_neuburg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@matt\_neuburg](https://www.ruby-forum.com/u/matt_neuburg)\
**Post date:** [January 27, 2008, 6:47pm UTC](https://www.ruby-forum.com/t/method-defined-doesnt-see-module-methods/127282/1 "2008-01-27T18:47:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![matt\_neuburg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@matt\_neuburg](https://www.ruby-forum.com/u/matt_neuburg)\
**Post date:** [January 27, 2008, 8:34pm UTC](https://www.ruby-forum.com/t/method-defined-doesnt-see-module-methods/127282/2 "2008-01-27T20:34:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![matt\_neuburg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@matt\_neuburg](https://www.ruby-forum.com/u/matt_neuburg)\
**Post date:** [January 27, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/method-defined-doesnt-see-module-methods/127282/3 "2008-01-27T22:10:40Z")

</div>

Stefano C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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.
