Class: Concurrent::Actors::Actor::Mailbox::Filter
- Inherits:
-
Object
- Object
- Concurrent::Actors::Actor::Mailbox::Filter
- Defined in:
- lib/concurrent/actors/mailbox.rb
Instance Method Summary collapse
- #action_for(value) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Filter
constructor
A new instance of Filter.
- #when(pattern, &action) ⇒ Object
Constructor Details
#initialize ⇒ Filter
Returns a new instance of Filter.
125 126 127 |
# File 'lib/concurrent/actors/mailbox.rb', line 125 def initialize @pairs = [] end |
Instance Method Details
#action_for(value) ⇒ Object
134 135 136 137 |
# File 'lib/concurrent/actors/mailbox.rb', line 134 def action_for(value) pair = @pairs.find { |pattern, action| pattern === value } pair ? pair[1] : nil end |
#empty? ⇒ Boolean
139 140 141 |
# File 'lib/concurrent/actors/mailbox.rb', line 139 def empty? @pairs.empty? end |
#when(pattern, &action) ⇒ Object
129 130 131 132 |
# File 'lib/concurrent/actors/mailbox.rb', line 129 def when(pattern, &action) raise ArgumentError, "no block given" unless action @pairs.push [pattern, action] end |