Class: Guileless::OutputBuffer
- Inherits:
-
Object
- Object
- Guileless::OutputBuffer
- Defined in:
- lib/guileless/output_buffer.rb
Instance Method Summary collapse
- #add(str) ⇒ Object
- #buffered? ⇒ Boolean
- #flush ⇒ Object
-
#initialize ⇒ OutputBuffer
constructor
A new instance of OutputBuffer.
- #to_s ⇒ Object
- #wrap(prefix, postfix) ⇒ Object
Constructor Details
#initialize ⇒ OutputBuffer
Returns a new instance of OutputBuffer.
3 4 5 6 |
# File 'lib/guileless/output_buffer.rb', line 3 def initialize @output_buffer = [] @output = [] end |
Instance Method Details
#add(str) ⇒ Object
8 9 10 11 12 |
# File 'lib/guileless/output_buffer.rb', line 8 def add(str) str = str.chars.to_a if str.kind_of?(String) @output_buffer += Array(str) str end |
#buffered? ⇒ Boolean
14 15 16 |
# File 'lib/guileless/output_buffer.rb', line 14 def buffered? @output_buffer.length > 0 end |
#flush ⇒ Object
18 19 20 21 |
# File 'lib/guileless/output_buffer.rb', line 18 def flush @output += @output_buffer @output_buffer = [] end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/guileless/output_buffer.rb', line 29 def to_s @output.join end |
#wrap(prefix, postfix) ⇒ Object
23 24 25 26 27 |
# File 'lib/guileless/output_buffer.rb', line 23 def wrap(prefix, postfix) prefix = prefix.chars.to_a if prefix.kind_of?(String) postfix = postfix.chars.to_a if postfix.kind_of?(String) @output_buffer = Array(prefix) + @output_buffer + Array(postfix) end |