Class: Microstation::EventHandler
- Inherits:
-
Object
- Object
- Microstation::EventHandler
show all
- Defined in:
- lib/microstation/event_handler.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of EventHandler.
4
5
6
|
# File 'lib/microstation/event_handler.rb', line 4
def initialize
@handlers = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(event, *args) ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/microstation/event_handler.rb', line 18
def method_missing(event, *args)
if @handlers[event.to_s]
@handlers[event.to_s].call(*args)
else
puts "Unhandled event: #{event} args: #{args}"
super
end
end
|
Instance Method Details
#add_handler(event, &block) ⇒ Object
8
9
10
11
12
|
# File 'lib/microstation/event_handler.rb', line 8
def add_handler(event, &block)
if block_given?
@handlers[event] = block
end
end
|
#get_handler(event) ⇒ Object
14
15
16
|
# File 'lib/microstation/event_handler.rb', line 14
def get_handler(event)
@handlers[event]
end
|