Class: OutputCatcher

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

Class Method Summary collapse

Class Method Details

.catch_err(&block) ⇒ Object



22
23
24
# File 'lib/output_catcher.rb', line 22

def catch_err(&block)
  catch_io("err", &block)
end

.catch_io(post, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/output_catcher.rb', line 6

def catch_io(post, &block)
  original = eval("$std" + post)
  fake     = StringIO.new
  eval("$std#{post} = fake")
  begin
    yield
  ensure
    eval("$std#{post} = original")
  end
  fake.string
end

.catch_out(&block) ⇒ Object



18
19
20
# File 'lib/output_catcher.rb', line 18

def catch_out(&block)
  catch_io("out", &block)
end