Class: WIN32OLE_EVENT
- Inherits:
-
Object
- Object
- WIN32OLE_EVENT
- Defined in:
- lib/win32ole/win32ole_event.rb
Class Method Summary collapse
-
.message_loop ⇒ Object
Almost noop this.
Instance Method Summary collapse
-
#initialize(ole, event_name = nil) ⇒ WIN32OLE_EVENT
constructor
A new instance of WIN32OLE_EVENT.
- #method_missing(name, *args) ⇒ Object
- #on_event(name = nil, &block) ⇒ Object
Constructor Details
#initialize(ole, event_name = nil) ⇒ WIN32OLE_EVENT
Returns a new instance of WIN32OLE_EVENT.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/win32ole/win32ole_event.rb', line 4 def initialize(ole, event_name=nil) @event_handlers = {} raise TypeError.new("1st parameter must be WIN32OLE object") if !ole.kind_of? WIN32OLE if event_name.nil? # Default event name # TODO: get default event end dispatch = ole.dispatch DispatchEvents.new dispatch, RubyInvocationProxy.new(self), dispatch.program_id end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/win32ole/win32ole_event.rb', line 25 def method_missing(name, *args) name = name.to_s handler = @event_handlers[name] if handler handler.call *args elsif @default_handler @default_handler.call name, *args end end |
Class Method Details
.message_loop ⇒ Object
Almost noop this. We don’t because it get CPU hot when people put this in a hot loop!
37 38 39 |
# File 'lib/win32ole/win32ole_event.rb', line 37 def self. DispatchEvents. end |
Instance Method Details
#on_event(name = nil, &block) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/win32ole/win32ole_event.rb', line 17 def on_event(name=nil, &block) if name @event_handlers[name.to_s] = block else @default_handler = block end end |