Class: Celluloid::Handlers

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/handlers.rb

Instance Method Summary collapse

Constructor Details

#initializeHandlers

Returns a new instance of Handlers.


5
6
7
# File 'lib/celluloid/handlers.rb', line 5

def initialize
  @handlers = Set.new
end

Instance Method Details

#handle(*patterns, &block) ⇒ Object


9
10
11
12
13
14
# File 'lib/celluloid/handlers.rb', line 9

def handle(*patterns, &block)
  patterns.each do |pattern|
    handler = Handler.new pattern, block
    @handlers << handler
  end
end

#handle_message(message) ⇒ Object

Handle incoming messages


17
18
19
20
21
# File 'lib/celluloid/handlers.rb', line 17

def handle_message(message)
  handler = @handlers.find { |h| h.match(message) }
  handler.call message if handler
  handler
end