Class: EnumeratorQueue
- Inherits:
-
Object
- Object
- EnumeratorQueue
- Extended by:
- Forwardable
- Defined in:
- src/ruby/bin/math_server.rb
Overview
A EnumeratorQueue wraps a Queue to yield the items added to it.
Instance Method Summary collapse
- #each_item ⇒ Object
-
#initialize(sentinel) ⇒ EnumeratorQueue
constructor
A new instance of EnumeratorQueue.
Constructor Details
#initialize(sentinel) ⇒ EnumeratorQueue
Returns a new instance of EnumeratorQueue.
93 94 95 96 |
# File 'src/ruby/bin/math_server.rb', line 93 def initialize(sentinel) @q = Queue.new @sentinel = sentinel end |
Instance Method Details
#each_item ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'src/ruby/bin/math_server.rb', line 98 def each_item return enum_for(:each_item) unless block_given? loop do r = @q.pop break if r.equal?(@sentinel) fail r if r.is_a? Exception yield r end end |