Method: WinGui::Window#method_missing
- Defined in:
- lib/win_gui/window.rb
#method_missing(name, *args, &block) ⇒ Object
Since Window instances wrap actual window handles, they should directly support Win32 API functions manipulating these handles. Therefore, when unsupported instance method is invoked, we check if WinGui responds to such method, and if yes, call it with our window handle as a first argument. This gives us all handle-related WinGui functions as instance methods for Window instances, like so:
window.visible?
This API is much more Ruby-like compared to:
visible?(window.handle)
Of course, if we invoke WinGui function that DOESN’T accept handle as a first arg this way, we are screwed. Call such functions only like this:
WinGui.function(*args)
TODO: Such setup is problematic if WinGui is included into Window ancestor chain. TODO: In this case, all WinGui functions become available as instance methods, and method_missing never fires. TODO: It may be a better solution to explicitly define all needed instance methods, TODO: instead of showing off cool meta-programming skillz. ;-)
198 199 200 201 202 203 204 205 |
# File 'lib/win_gui/window.rb', line 198 def method_missing(name, *args, &block) if WinGui.respond_to? name # puts "Window #{@handle} calling: #{name} #{@handle} #{args} &#{block}" WinGui.send(name, @handle, *args, &block) else super end end |