Because when a GUI button is clicked, I need to call a particular
method of a particular class. I don't think I can give it an
argument.
Actually, (I'm using Glade) I have this:
app_window = AppWindow.new
GladeXML.new("app.glade") { |handler| app_window.method(handler) }
Where AppWindow is a class that contains all the methods that are
defined in the glade file. In the glade file are methods being
registered like "menu_zoom_250_activate", "menu_zoom_500_activate" and
so on.
If a particular method that's contained in the glade file isn't
defined in the AppWindow class, I get a "undefined method '<some
method>' for class AppWindow" upon the start of the application.
I added AppWindow#method_missing that just prints out the missing
method, but that didn't seem to solve anything.
Perhaps it would be best to have a single method in AppWindow that
took all the methods (as a string) that were defined in the glade file
and executed the appropriate action?
So,
GladeXML.new("app.glade") { |handler| app_window.execute_method(handler) }
class AppWindow
def execute_method(method)
case method
when /menu_zoom_(\d+)_activate/
@display.zoom($1.to_i)
when "something_else"
# do something else
end
end
end