J
Joe Van Dyk
class Parent
def foo
puts "Parent::foo called"
end
end
module TheModule=20
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 i=
n
# to Child?
#
# 2) Any way I can get TheModule.boo to call Parent.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 =3D create_menu "File"
add_menu_item(file_menu, "Quit") { exit }
end
end
def foo
puts "Parent::foo called"
end
end
module TheModule=20
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 i=
n
# to Child?
#
# 2) Any way I can get TheModule.boo to call Parent.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 =3D create_menu "File"
add_menu_item(file_menu, "Quit") { exit }
end
end