Class: Microstation::EventHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/microstation/event_handler.rb

Instance Method Summary collapse

Constructor Details

#initializeEventHandler

Returns a new instance of EventHandler.



3
4
5
# File 'lib/microstation/event_handler.rb', line 3

def initialize
  @handlers = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(event, *args) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/microstation/event_handler.rb', line 15

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



7
8
9
# File 'lib/microstation/event_handler.rb', line 7

def add_handler(event, &block)
  @handlers[event] = block if block
end

#get_handler(event) ⇒ Object



11
12
13
# File 'lib/microstation/event_handler.rb', line 11

def get_handler(event)
  @handlers[event]
end