Class: Celluloid::Internals::Handlers

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

Instance Method Summary collapse

Constructor Details

#initializeHandlers

Returns a new instance of Handlers.



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

def initialize
  @handlers = Set.new
end

Instance Method Details

#handle(*patterns, &block) ⇒ Object



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

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

#handle_message(message) ⇒ Object

Handle incoming messages



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

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