Class: Greener::OutputBuffer
- Inherits:
-
Object
- Object
- Greener::OutputBuffer
- Defined in:
- lib/greener/output_buffer.rb
Overview
Initialize this class to delay output, gist.github.com/macek/596007
Class Attribute Summary collapse
-
.original_stdout ⇒ Object
Returns the value of attribute original_stdout.
Class Method Summary collapse
Instance Method Summary collapse
- #activate ⇒ Object
-
#initialize ⇒ OutputBuffer
constructor
A new instance of OutputBuffer.
- #stop ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ OutputBuffer
Returns a new instance of OutputBuffer.
6 7 8 9 |
# File 'lib/greener/output_buffer.rb', line 6 def initialize @buffer = StringIO.new activate end |
Class Attribute Details
.original_stdout ⇒ Object
Returns the value of attribute original_stdout.
28 29 30 |
# File 'lib/greener/output_buffer.rb', line 28 def original_stdout @original_stdout end |
Class Method Details
.restore_default ⇒ Object
30 31 32 |
# File 'lib/greener/output_buffer.rb', line 30 def restore_default $stdout = original_stdout end |
Instance Method Details
#activate ⇒ Object
11 12 13 14 15 16 |
# File 'lib/greener/output_buffer.rb', line 11 def activate return if @activated self.class.original_stdout = $stdout $stdout = @buffer @activated = true end |
#stop ⇒ Object
23 24 25 |
# File 'lib/greener/output_buffer.rb', line 23 def stop self.class.restore_default end |
#to_s ⇒ Object
18 19 20 21 |
# File 'lib/greener/output_buffer.rb', line 18 def to_s @buffer.rewind @buffer.read end |