Re: Ncurses module inclusion question
- From: John Pritchard-williams <monojohnny@xxxxxxxxxxxxxx>
- Date: Fri, 29 Aug 2008 14:14:00 -0500
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 Programming 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 ;-)
--
Posted via http://www.ruby-forum.com/.
.
- Prev by Date: Does Ruby optimize tail-call recursion?
- Next by Date: Re: Does Ruby optimize tail-call recursion?
- Previous by thread: Does Ruby optimize tail-call recursion?
- Next by thread: assignment operator that treats empty and nil as the same thing
- Index(es):
Relevant Pages
|