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

**URL:** <https://rubytalk.org/t/method-defined-doesnt-see-module-methods/44065>\
**Category:** ruby-talk\
**Created:** [27 January 2008 17:44 UTC](https://rubytalk.org/t/method-defined-doesnt-see-module-methods/44065 "2008-01-27T17:44:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt9](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Matt9](https://rubytalk.org/u/Matt9)\
**Post date:** [27 January 2008 17:44 UTC](https://rubytalk.org/t/method-defined-doesnt-see-module-methods/44065/1 "2008-01-27T17:44:58Z")

</div>

module M  
&nbsp;&nbsp;def self.howdy  
&nbsp;&nbsp;&nbsp;&nbsp;"hello"  
&nbsp;&nbsp;end  
end  
p M.method\_defined? :howdy #=\> false

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

> **···**
>
> --  
> matt neuburg, phd = [matt@tidbits.com](mailto:matt@tidbits.com), [http://www.tidbits.com/matt/](http://www.tidbits.com/matt/)  
> Leopard - [http://www.takecontrolbooks.com/leopard-customizing.html](http://www.takecontrolbooks.com/leopard-customizing.html)  
> AppleScript - [http://www.amazon.com/gp/product/0596102119](http://www.amazon.com/gp/product/0596102119)  
> Read TidBITS! It's free and smart. [http://www.tidbits.com](http://www.tidbits.com)

---

<div class="post-metadata">

**Author:** ![Stefano\_Crocco](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Stefano\_Crocco](https://rubytalk.org/u/Stefano_Crocco)\
**Post date:** [27 January 2008 19:33 UTC](https://rubytalk.org/t/method-defined-doesnt-see-module-methods/44065/2 "2008-01-27T19:33:22Z")

</div>

Alle Sunday 27 January 2008, matt neuburg ha scritto:

> module M  
> &nbsp;&nbsp;def self.howdy  
> &nbsp;&nbsp;&nbsp;&nbsp;"hello"  
> &nbsp;&nbsp;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:** ![Matt9](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Matt9](https://rubytalk.org/u/Matt9)\
**Post date:** [27 January 2008 21:09 UTC](https://rubytalk.org/t/method-defined-doesnt-see-module-methods/44065/3 "2008-01-27T21:09:57Z")

</div>

Excellent, thanks! m.

> **···**
>
> Stefano Crocco \<stefano.crocco@alice.it\> wrote:
> 
> > 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.
> > 
> > To know whether the module has a module method, you can use respond\_to? on the  
> > module:
> > 
> > M.respond\_to?(:howdy)  
> > =\> true
> 
> --  
> matt neuburg, phd = matt@tidbits.com, [Matt Neuburg’s Home Page](http://www.tidbits.com/matt/)  
> Leopard - [http://www.takecontrolbooks.com/leopard-customizing.html](http://www.takecontrolbooks.com/leopard-customizing.html)  
> AppleScript - [http://www.amazon.com/gp/product/0596102119](http://www.amazon.com/gp/product/0596102119)  
> Read TidBITS! It's free and smart. [http://www.tidbits.com](http://www.tidbits.com)
