Class: Wmiirc::Handler
- Inherits:
-
Hash
- Object
- Hash
- Wmiirc::Handler
- Defined in:
- lib/wmiirc/handler.rb
Instance Method Summary (collapse)
-
- (Object) handle(key, *args, &block)
Registers the given block as a handler for the given key and returns that handler, or if a block is not given, executes all handlers registered for the given key.
-
- (Handler) initialize
constructor
A new instance of Handler.
Constructor Details
- (Handler) initialize
Returns a new instance of Handler
5 6 7 |
# File 'lib/wmiirc/handler.rb', line 5 def initialize super {|h,k| h[k] = [] } end |
Instance Method Details
- (Object) handle(key, *args, &block)
Registers the given block as a handler for the given key and returns that handler, or if a block is not given, executes all handlers registered for the given key.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/wmiirc/handler.rb', line 14 def handle key, *args, &block if block self[key] << block elsif key? key self[key].each do |block| begin block.call(*args) rescue LocalJumpError => error # let handlers return early, just like methods raise unless error. == 'unexpected return' end end end block end |