Class: CatchAndRelease::Catch::Stdout
- Inherits:
-
Object
- Object
- CatchAndRelease::Catch::Stdout
- Defined in:
- lib/catch_and_release/catch.rb
Instance Attribute Summary collapse
-
#new_stdout ⇒ Object
readonly
Returns the value of attribute new_stdout.
-
#orig_stdout ⇒ Object
readonly
Returns the value of attribute orig_stdout.
Instance Method Summary collapse
- #capture(&block) ⇒ Object
-
#initialize ⇒ Stdout
constructor
A new instance of Stdout.
- #read ⇒ Object
Constructor Details
#initialize ⇒ Stdout
Returns a new instance of Stdout.
22 23 24 25 |
# File 'lib/catch_and_release/catch.rb', line 22 def initialize @orig_stdout = $stdout @new_stdout = StringIO.new end |
Instance Attribute Details
#new_stdout ⇒ Object (readonly)
Returns the value of attribute new_stdout.
20 21 22 |
# File 'lib/catch_and_release/catch.rb', line 20 def new_stdout @new_stdout end |
#orig_stdout ⇒ Object (readonly)
Returns the value of attribute orig_stdout.
19 20 21 |
# File 'lib/catch_and_release/catch.rb', line 19 def orig_stdout @orig_stdout end |
Instance Method Details
#capture(&block) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/catch_and_release/catch.rb', line 27 def capture &block $stdout = new_stdout yield return self ensure $stdout = orig_stdout end |
#read ⇒ Object
35 36 37 38 |
# File 'lib/catch_and_release/catch.rb', line 35 def read new_stdout.rewind new_stdout.read end |