Ncurses module inclusion question

Discussion in 'Ruby' started by Jos Backus, Aug 29, 2008.

  1. Jos Backus

    Jos Backus Guest

    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?

    --
    Jos Backus
    jos at catnook.com
     
    Jos Backus, Aug 29, 2008
    #1
    1. Advertising

  2. 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/.
     
    John Pritchard-williams, Aug 29, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johannes Bauer

    Header inclusion question

    Johannes Bauer, Dec 7, 2004, in forum: C++
    Replies:
    6
    Views:
    432
    EventHelix.com
    Dec 8, 2004
  2. Mark J. Reed
    Replies:
    0
    Views:
    93
    Mark J. Reed
    Feb 18, 2005
  3. Trans
    Replies:
    2
    Views:
    85
    Trans
    Aug 31, 2007
  4. Kenneth McDonald
    Replies:
    1
    Views:
    152
    Nit Khair
    Sep 27, 2008
  5. Rolf Pedersen
    Replies:
    6
    Views:
    167
    Paolo Perrotta
    Jul 28, 2010
Loading...

Share This Page