Class: IRB::CaptureIO
- Inherits:
-
Object
- Object
- IRB::CaptureIO
- Defined in:
- lib/irb_rocket.rb
Instance Method Summary collapse
- #capture(&block) ⇒ Object
-
#initialize ⇒ CaptureIO
constructor
A new instance of CaptureIO.
- #play ⇒ Object
- #print(*args) ⇒ Object
Constructor Details
#initialize ⇒ CaptureIO
Returns a new instance of CaptureIO.
9 10 11 12 13 |
# File 'lib/irb_rocket.rb', line 9 def initialize @sin, @sout = IO.pipe @ein, @eout = IO.pipe @out, @err = STDOUT.dup, STDERR.dup end |
Instance Method Details
#capture(&block) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/irb_rocket.rb', line 15 def capture(&block) STDOUT.reopen(@sout) STDERR.reopen(@eout) block.call ensure play STDOUT.reopen(@out) STDERR.reopen(@err) end |
#play ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/irb_rocket.rb', line 29 def play play_io(@ein) do |buf| @err.print Wirble::Colorize::Color.escape(:red) + buf + "\e[m" end play_io(@sin) do |buf| @out.print buf end end |
#print(*args) ⇒ Object
25 26 27 |
# File 'lib/irb_rocket.rb', line 25 def print(*args) @out.print(*args) end |