Class: ThomasUtils::ObjectStream
- Inherits:
-
Object
- Object
- ThomasUtils::ObjectStream
- Defined in:
- lib/thomas_utils/object_stream.rb
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #flush ⇒ Object
-
#initialize(&callback) ⇒ ObjectStream
constructor
A new instance of ObjectStream.
Constructor Details
#initialize(&callback) ⇒ ObjectStream
Returns a new instance of ObjectStream.
4 5 6 7 |
# File 'lib/thomas_utils/object_stream.rb', line 4 def initialize(&callback) @buffer = Queue.new @callback = callback end |
Instance Method Details
#<<(item) ⇒ Object
9 10 11 |
# File 'lib/thomas_utils/object_stream.rb', line 9 def <<(item) @buffer << item end |
#flush ⇒ Object
13 14 15 16 17 |
# File 'lib/thomas_utils/object_stream.rb', line 13 def flush length = @buffer.size items = length.times.map { @buffer.pop } @callback.call(items) end |