Class: IRB::CaptureIO
- Inherits:
-
Object
- Object
- IRB::CaptureIO
- Defined in:
- lib/irb_rocket.rb
Class Method Summary collapse
Instance Method Summary collapse
- #capture(&block) ⇒ Object
-
#initialize ⇒ CaptureIO
constructor
A new instance of CaptureIO.
- #play ⇒ Object
- #print(*args) ⇒ Object
Constructor Details
#initialize ⇒ 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 |
Class Method Details
.original_streams ⇒ Object
15 16 17 18 19 20 |
# File 'lib/irb_rocket.rb', line 15 def self.original_streams { :stdout => @@current_capture.instance_variable_get( :@out ), :stderr => @@current_capture.instance_variable_get( :@err ), } end |
Instance Method Details
#capture(&block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/irb_rocket.rb', line 22 def capture(&block) @@current_capture = self STDOUT.reopen(@sout) STDERR.reopen(@eout) block.call ensure play STDOUT.reopen(@out) STDERR.reopen(@err) end |
#play ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/irb_rocket.rb', line 37 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
33 34 35 |
# File 'lib/irb_rocket.rb', line 33 def print(*args) @out.print(*args) end |