# Module "re-opening"

**URL:** <https://www.ruby-forum.com/t/module-re-opening/187288>\
**Category:** Ruby\
**Created:** [April 21, 2010, 7:56am UTC](https://www.ruby-forum.com/t/module-re-opening/187288 "2010-04-21T07:56:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tilde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@tilde](https://www.ruby-forum.com/u/tilde)\
**Post date:** [April 21, 2010, 7:56am UTC](https://www.ruby-forum.com/t/module-re-opening/187288/1 "2010-04-21T07:56:26Z")

</div>

Hi there, first time arond here for me, and first step with ruby ^^

well, i come with a simple (maybe stupid) question:

[http://sprunge.us/BjJP?rb](http://sprunge.us/BjJP?rb)

why this simple source doesn’t do what is expected? (modify the  
visibility of sqrt module)

thx in advance for any answer ^^

bye  
M

---

<div class="post-metadata">

**Author:** ![tilde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@tilde](https://www.ruby-forum.com/u/tilde)\
**Post date:** [April 21, 2010, 8:33am UTC](https://www.ruby-forum.com/t/module-re-opening/187288/2 "2010-04-21T08:33:20Z")

</div>

tilde wrote:

> bye  
> M

i mean, sqrt _method_, sorry

---

<div class="post-metadata">

**Author:** ![tilde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@tilde](https://www.ruby-forum.com/u/tilde)\
**Post date:** [April 21, 2010, 9:04am UTC](https://www.ruby-forum.com/t/module-re-opening/187288/3 "2010-04-21T09:04:22Z")

</div>

On Wed, Apr 21, 2010 at 7:55 AM, tilde [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi there, first time arond here for me, and first step with ruby ^^
> 
> well, i come with a simple (maybe stupid) question:
> 
> [http://sprunge.us/BjJP?rb](http://sprunge.us/BjJP?rb)

(copying it here since it’s small):

1 #! /usr/bin/env ruby1.9  
2  
3 module Math  
4 private :sqrt  
5 end  
6  
7 puts Math.sqrt(9)

> why this simple source doesn’t do what is expected? (modify the visibility  
> of sqrt module)

Because sqrt is a module method:

irb(main):001:0\> module Math  
irb(main):002:1\> class \<\< self  
irb(main):003:2\> private :sqrt  
irb(main):004:2\> end  
irb(main):005:1\> end  
=\> #Class:Math  
irb(main):006:0\> Math.sqrt(9)  
NoMethodError: private method `sqrt’ called for Math:Module  
from (irb):6  
from :0

Jesus.

---

<div class="post-metadata">

**Author:** ![tilde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@tilde](https://www.ruby-forum.com/u/tilde)\
**Post date:** [April 21, 2010, 9:21am UTC](https://www.ruby-forum.com/t/module-re-opening/187288/4 "2010-04-21T09:21:56Z")

</div>

On Apr 20, 2010, at 22:55 , tilde wrote:

> Hi there, first time arond here for me, and first step with ruby ^^
> 
> well, i come with a simple (maybe stupid) question:
> 
> [http://sprunge.us/BjJP?rb](http://sprunge.us/BjJP?rb)
> 
> why this simple source doesn’t do what is expected? (modify the visibility of sqrt module)
> 
> thx in advance for any answer ^^

It is essentially a class method, so you need to invoke private at the  
class level:

> > module Math; class \<\< self; private :sqrt; end; end  
> > Math.sqrt 42  
> > NoMethodError: private method `sqrt’ called for Math:Module

---

<div class="post-metadata">

**Author:** ![tilde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@tilde](https://www.ruby-forum.com/u/tilde)\
**Post date:** [April 21, 2010, 8:15pm UTC](https://www.ruby-forum.com/t/module-re-opening/187288/5 "2010-04-21T20:15:56Z")

</div>

Ryan D. wrote:

> > thx in advance for any answer ^^
> 
> It is essentially a class method, so you need to invoke private at the class level:
> 
> > > module Math; class \<\< self; private :sqrt; end; end  
> > > Math.sqrt 42  
> > > NoMethodError: private method `sqrt’ called for Math:Module

I see… thx to all ^^
