From: Zach Dennis Date: 2005-08-02T07:04:53+09:00 Subject: Re: module / inheritance question Joe Van Dyk wrote: > class Parent > def foo > puts "Parent::foo called" > end > end > > module TheModule > def self.boo > foo > end > end > > class Child < Parent > include TheModule > def initialize > super > end > > def boo > TheModule.boo > end > end > > Child.new.boo > > # Two questions: > # 1) Why do I need Child.boo? Shouldn't function TheModule.boo be mixed in > # to Child? Because you defined boo as a module method on TheModule. Instance methods are mixed into classes: module TheModule def boo end end > # 2) Any way I can get TheModule.boo to call Parent.foo? class Parent def foo "foo" end end module M def boo foo end end class Child < Parent include M end Child.new.boo => "foo" > # > # > # What I'm really trying to do is something like this: > > module MenuBarUtils > def create_menu title > # Creates a Gtk::Menu and then calls #append, a function that's in > # Gtk::MenuBar. > end > def add_menu_item menu, title, &action > # create menu item, attach it to menu, and bind &action to it > end > end > > class MyMenuBar < Gtk::MenuBar > include MenuBarUtils > def initialize > super > file_menu = create_menu "File" > add_menu_item(file_menu, "Quit") { exit } > end > end this appears to work fine... just change the definition of TheModule.boo to TheModule#boo Zach