Class: Rubinius::Actor::Filter
- Inherits:
-
Object
- Object
- Rubinius::Actor::Filter
- Defined in:
- lib/rubinius/actor/filter.rb
Instance Attribute Summary collapse
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#timeout_action ⇒ Object
readonly
Returns the value of attribute timeout_action.
Instance Method Summary collapse
- #action_for(value) ⇒ Object
- #after(seconds, &action) ⇒ Object
-
#initialize ⇒ Filter
constructor
A new instance of Filter.
- #timeout? ⇒ Boolean
- #when(pattern, &action) ⇒ Object
Constructor Details
#initialize ⇒ Filter
Returns a new instance of Filter.
37 38 39 40 41 |
# File 'lib/rubinius/actor/filter.rb', line 37 def initialize @pairs = [] @timeout = nil @timeout_action = nil end |
Instance Attribute Details
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
34 35 36 |
# File 'lib/rubinius/actor/filter.rb', line 34 def timeout @timeout end |
#timeout_action ⇒ Object (readonly)
Returns the value of attribute timeout_action.
35 36 37 |
# File 'lib/rubinius/actor/filter.rb', line 35 def timeout_action @timeout_action end |
Instance Method Details
#action_for(value) ⇒ Object
64 65 66 67 |
# File 'lib/rubinius/actor/filter.rb', line 64 def action_for(value) pair = @pairs.find { |pattern, action| pattern === value } pair ? pair.last : nil end |
#after(seconds, &action) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rubinius/actor/filter.rb', line 53 def after(seconds, &action) raise ArgumentError, "no block given" unless action seconds = seconds.to_f if !@timeout or seconds < @timeout @timeout = seconds @timeout_action = action end self end |
#timeout? ⇒ Boolean
43 44 45 |
# File 'lib/rubinius/actor/filter.rb', line 43 def timeout? not @timeout.nil? end |
#when(pattern, &action) ⇒ Object
47 48 49 50 51 |
# File 'lib/rubinius/actor/filter.rb', line 47 def when(pattern, &action) raise ArgumentError, "no block given" unless action @pairs.push [pattern, action] self end |