Class: Complate::Stream
- Inherits:
-
Enumerator
- Object
- Enumerator
- Complate::Stream
- Defined in:
- lib/complate/stream.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #flush(*_) ⇒ Object
-
#initialize(&block) ⇒ Stream
constructor
A new instance of Stream.
- #write(str) ⇒ Object
- #writeln(str) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Stream
Returns a new instance of Stream.
3 4 5 6 |
# File 'lib/complate/stream.rb', line 3 def initialize(&block) @after_start = block @buf = '' end |
Instance Method Details
#each(&block) ⇒ Object
16 17 18 19 20 |
# File 'lib/complate/stream.rb', line 16 def each(&block) @block = block @after_start.call(self) flush end |
#flush(*_) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/complate/stream.rb', line 22 def flush(*_) if @block && @buf != '' @block.call(@buf) @buf = '' end end |
#write(str) ⇒ Object
12 13 14 |
# File 'lib/complate/stream.rb', line 12 def write(str) @buf << str end |
#writeln(str) ⇒ Object
8 9 10 |
# File 'lib/complate/stream.rb', line 8 def writeln(str) write("#{str}\n") end |