# Best way to create a helper method

**URL:** <https://www.ruby-forum.com/t/best-way-to-create-a-helper-method/145926>\
**Category:** Ruby\
**Created:** [August 15, 2008, 3:52am UTC](https://www.ruby-forum.com/t/best-way-to-create-a-helper-method/145926 "2008-08-15T03:52:16Z")\
**Posts on this page:** 5\
**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 15, 2008, 3:52am UTC](https://www.ruby-forum.com/t/best-way-to-create-a-helper-method/145926/1 "2008-08-15T03:52:16Z")

</div>

What would you guys say is the best way of creating a helper method?

module MyModule  
def myMethod  
#bla bla  
end  
end

def helperMethod  
#a helper method whose existence should not be known outside of this  
file  
end

helperMethod() shouldn’t be visible from anywhere outside this file.

Thanks for helping me with this  
-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 15, 2008, 3:55pm UTC](https://www.ruby-forum.com/t/best-way-to-create-a-helper-method/145926/2 "2008-08-15T15:55:42Z")

</div>

Patrick Li wrote:

> file  
> end
> 
> helperMethod() shouldn’t be visible from anywhere outside this file.

Can you put helperMethod inside MyModule, and make it private? I don’t  
know if  
the language supports that.

And you may want to consider unit tests as more important than static  
type  
checking, to keep a program on track…

---

<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 15, 2008, 4:13pm UTC](https://www.ruby-forum.com/t/best-way-to-create-a-helper-method/145926/3 "2008-08-15T16:13:15Z")

</div>

I can:

module MyModule  
def myMethod  
#bla bla  
end

private  
def helperMethod  
#a helper method whose existence should not be known outside of this  
file  
end  
end

But I can still get access to helperMethod by mixing in the module.

eg.  
class MyClass  
include MyModule #I want myMethod() but not helperMethod()  
end

Thanks for replying  
-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 15, 2008, 4:30pm UTC](https://www.ruby-forum.com/t/best-way-to-create-a-helper-method/145926/4 "2008-08-15T16:30:55Z")

</div>

> But I can still get access to helperMethod by mixing in the module.

protected ?

---

<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 15, 2008, 5:10pm UTC](https://www.ruby-forum.com/t/best-way-to-create-a-helper-method/145926/5 "2008-08-15T17:10:48Z")

</div>

Patrick Li wrote:

> But I can still get access to helperMethod by mixing in the module.

Private methods are not a form of code security. Even if you made this  
method  
completely private, you can still get to it with .send(:helperMethod).

No language makes any private method absolutely private. You should  
think of  
privacy as nothing more than a warning - “please reconsider calling this  
method”. Another common way to do that is move the method out of the  
default  
namespace by calling it \_helperMethod.
