Class: StIO

Inherits:
Object
  • Object
show all
Defined in:
lib/code_writer/rbmarkdown.rb

Overview

In some cases, there is the need to redirect standard output to a string. In general class StIO will do it without any problem. However, when integrating with some libraries, for instace, Renjin, Renjin standard output and Ruby standard output are different, so we need to redirect both standard outputs to the same string. The integrating library will have to implement methods set_std_out, set_std_err, set_default_std_out and set_default_std_err.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#alternate_errObject (readonly)

Returns the value of attribute alternate_err.



25
26
27
# File 'lib/code_writer/rbmarkdown.rb', line 25

def alternate_err
  @alternate_err
end

#alternate_outObject (readonly)

Returns the value of attribute alternate_out.



24
25
26
# File 'lib/code_writer/rbmarkdown.rb', line 24

def alternate_out
  @alternate_out
end

Instance Method Details

#set_default_std_outObject



37
38
39
# File 'lib/code_writer/rbmarkdown.rb', line 37

def set_default_std_out
  $stdout = STDOUT
end

#set_std_err(buffer) ⇒ Object



32
33
34
35
# File 'lib/code_writer/rbmarkdown.rb', line 32

def set_std_err(buffer)
  $stderr = StringIO.new(buffer)
  @alternate_err = buffer
end

#set_std_out(buffer) ⇒ Object



27
28
29
30
# File 'lib/code_writer/rbmarkdown.rb', line 27

def set_std_out(buffer)
  $stdout = StringIO.new(buffer)
  @alternate_out = buffer
end