Class: Relayer::IRCEvents
- Inherits:
-
Object
- Object
- Relayer::IRCEvents
- Defined in:
- lib/relayer/events.rb
Instance Method Summary collapse
- #dispatch(event, args) ⇒ Object
-
#initialize(protocol, client) ⇒ IRCEvents
constructor
A new instance of IRCEvents.
- #method_missing(event, *args, &handler) ⇒ Object
Constructor Details
#initialize(protocol, client) ⇒ IRCEvents
Returns a new instance of IRCEvents.
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/relayer/events.rb', line 3 def initialize(protocol, client) @protocol = protocol @client = client @handlers = { :ping => [], :connected => [], :channel_msg => [], :ctcp => [] } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(event, *args, &handler) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/relayer/events.rb', line 15 def method_missing(event, *args, &handler) raise ArgumentError if handler.nil? if @handlers.has_key? event @handlers[event].push handler else raise NoMethodError end end |
Instance Method Details
#dispatch(event, args) ⇒ Object
25 26 27 28 29 |
# File 'lib/relayer/events.rb', line 25 def dispatch(event, args) @handlers[event].each do |handler| handler.call(@protocol, args) end end |