# Module\_function

**URL:** <https://www.ruby-forum.com/t/module-function/145314>\
**Category:** Ruby\
**Created:** [August 7, 2008, 9:26pm UTC](https://www.ruby-forum.com/t/module-function/145314 "2008-08-07T21:26:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lynchnco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@lynchnco](https://www.ruby-forum.com/u/lynchnco)\
**Post date:** [August 7, 2008, 9:26pm UTC](https://www.ruby-forum.com/t/module-function/145314/1 "2008-08-07T21:26:01Z")

</div>

Hi,  
I’m having some trouble using module\_function correctly. If someone  
could help me it’d be great.

I have a module M that defines method a().  
I would like for a() to be callable by M.a() or include M; a();

However (and this is where my problem lies)  
a() calls the helper method b().

module M  
module\_function  
def a  
b  
end

private  
def b  
#helper method  
end  
end

This throws a NoMethodError when I try to call M.a(), because it looks  
for M.b() (but there isn’t and shouldn’t be any).

What’s the normal way for resolving this?  
Thanks a lot for your help  
-patrick

---

<div class="post-metadata">

**Author:** ![lynchnco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@lynchnco](https://www.ruby-forum.com/u/lynchnco)\
**Post date:** [August 8, 2008, 12:06am UTC](https://www.ruby-forum.com/t/module-function/145314/2 "2008-08-08T00:06:26Z")

</div>

On Aug 7, 3:24 pm, Patrick Li [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> module M
> 
> This throws a NoMethodError when I try to call M.a(), because it looks  
> for M.b() (but there isn’t and shouldn’t be any).
> 
> What’s the normal way for resolving this?

One way is to say, “to hell with module\_function”:

module M  
extend self

```
def a
  b
end

private
def b
  #helper method
end

```

end

T.
