# Ncurses module inclusion question

**URL:** <https://www.ruby-forum.com/t/ncurses-module-inclusion-question/147248>\
**Category:** Ruby\
**Created:** [August 29, 2008, 8:35pm UTC](https://www.ruby-forum.com/t/ncurses-module-inclusion-question/147248 "2008-08-29T20:35:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jos\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@Jos\_B](https://www.ruby-forum.com/u/Jos_B)\
**Post date:** [August 29, 2008, 8:35pm UTC](https://www.ruby-forum.com/t/ncurses-module-inclusion-question/147248/1 "2008-08-29T20:35:56Z")

</div>

lizzy:~% cat n  
Math.sqrt(4)

include Math  
sqrt(4)

require ‘rubygems’  
require ‘ncurses’

Ncurses.initscr

include Ncurses  
initscr  
lizzy:~% ruby n 2\> err  
lizzy:~% cat err  
n:12: undefined local variable or method `initscr’ for main:Object  
(NameError)  
%  
lizzy:~%

Why does including Ncurses not have the same effect as including Math?

---

<div class="post-metadata">

**Author:** ![Jos\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@Jos\_B](https://www.ruby-forum.com/u/Jos_B)\
**Post date:** [August 29, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/ncurses-module-inclusion-question/147248/2 "2008-08-29T21:18:48Z")

</div>

Jos,

Its a weird quirky feature I don’t really understand - but managed to  
put together this: I have to guess that Ncurses is defining a ‘normal’  
module, whereas I know (from my book!) that the Math library used  
‘Module#module\_function’.

(My program but based on "The Ruby P.ming Language : ISBN-10:  
0-596-51617-7 , O’Reilly, Page 248 onwards (esp: page 251 “Includable  
Namespace Modules”).

Cheers

John

module Mymodule  
Module#module\_function  
def method1  
puts “method1 called”  
end  
end

module MyOtherModule  
def MyOtherModule.method2  
puts “method2 called”  
end  
end

include Mymodule  
include MyOtherModule  
Mymodule.method1  
method1 # this will work.  
MyOtherModule.method2  
method2 #this will fail

Also note: if you do:

include Math  
Object.respond\_to?(“sqrt”)

You’ll see that Object hasn’t really grown a new method at all - it’s  
all a big trick 😉

---

<div class="post-metadata">

**Author:** ![Jos\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@Jos\_B](https://www.ruby-forum.com/u/Jos_B)\
**Post date:** [August 30, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/ncurses-module-inclusion-question/147248/3 "2008-08-30T23:13:51Z")

</div>

Hi John,

Thanks for your response.

On Sat, Aug 30, 2008 at 04:14:00AM +0900, John Pritchard-williams wrote:

> Its a weird quirky feature I don’t really understand - but managed to  
> put together this: I have to guess that Ncurses is defining a ‘normal’  
> module, whereas I know (from my book!) that the Math library used  
> ‘Module#module\_function’.
> 
> (My program but based on "The Ruby P.ming Language : ISBN-10:  
> 0-596-51617-7 , O’Reilly, Page 248 onwards (esp: page 251 “Includable  
> Namespace Modules”).

Sadly I don’t have that book (yet).

> method1 # this will work.  
> MyOtherModule.method2  
> method2 #this will fail

Hm, `Module#module_function' seems to be parsed as `Module # comment’.  
Also,  
`def MyOtherModule.method2’defines a class method, no? At least, that’s  
what  
it would do if MyOtherModule were a class.

You sure you don’t just mean

```
module Mymodule
  def method1

```

puts “method1 called”  
end  
module\_function :method1  
end

(See  
[http://devclue.blogspot.com/2007/12/rubys-modulemodulefunction-method.html](http://devclue.blogspot.com/2007/12/rubys-modulemodulefunction-method.html))

Although it doesn’t seem to make a difference here.

> Also note: if you do:
> 
> include Math  
> Object.respond\_to?(“sqrt”)
> 
> You’ll see that Object hasn’t really grown a new method at all - it’s  
> all a big trick 😉

It’s magic 🙂 And confusing.
