# What's the Ruby Way to hide class helpers?

**URL:** <https://www.ruby-forum.com/t/whats-the-ruby-way-to-hide-class-helpers/66390>\
**Category:** Ruby\
**Created:** [August 25, 2006, 4:25am UTC](https://www.ruby-forum.com/t/whats-the-ruby-way-to-hide-class-helpers/66390 "2006-08-25T04:25:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [August 25, 2006, 4:25am UTC](https://www.ruby-forum.com/t/whats-the-ruby-way-to-hide-class-helpers/66390/1 "2006-08-25T04:25:46Z")

</div>

Start with:

class C  
def self.class\_callme  
internal\_helper  
end

def instance\_callme  
C.internal\_helper  
end

def self.internal\_helper  
puts “I’m not needed by the outside world.”  
end  
end

My first instinct was to make internal\_helper protected:

class \<\< self  
protected  
def internal\_helper  
puts “I’m not needed by the outside world.”  
end  
end

However, instance\_methods (such as instance\_callme) can’t call protected  
class methods.

Is there some other idiomatic Ruby way to, er, protect internal\_helper,  
or  
another way to call it from instance\_callme? Or do I just have to do it  
through lack of documentation with :nodoc:, as Rails seems to do?

Jay L.

---

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [August 25, 2006, 5:55am UTC](https://www.ruby-forum.com/t/whats-the-ruby-way-to-hide-class-helpers/66390/2 "2006-08-25T05:55:55Z")

</div>

Jay L. wrote:

> ```
> puts "I'm not needed by the outside world."
> 
> ```
> 
> Jay L.  
> Why not just stick internal\_helper in a nested module? (Or does  
> internal\_helper need to access class state?)

class C  
def self.class\_callme  
M.internal\_helper  
end

def instance\_callme  
M.internal\_helper  
end

module M  
def self.internal\_helper  
puts “I’m not needed by the outside world.”  
end  
end  
end

C.new.instance\_callme # ==\> I’m not needed by the outside world.

---

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [August 25, 2006, 2:20pm UTC](https://www.ruby-forum.com/t/whats-the-ruby-way-to-hide-class-helpers/66390/3 "2006-08-25T14:20:46Z")

</div>

On Fri, 25 Aug 2006 12:53:44 +0900, Joel VanderWerf wrote:

> Why not just stick internal\_helper in a nested module? (Or does  
> internal\_helper need to access class state?)

That works for me in the current case; internal\_helper routines don’t  
need  
any class state (and, in general, I try to avoid having any such state,  
rebelling against my C days of static variables).

Out of curiosity, though, if I did need my internal\_helper routine to  
get  
at state, what would you recommend? Seems like the only solution in  
Ruby  
is to extract the internals out to another object that’s only called by  
my  
public, interface object - but that seems so un-Rubyish.

Jay
