Module: IO::Grab

Included in:
IO, StringIO
Defined in:
lib/io/grab.rb,
lib/io/grab/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#grab(&block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/io/grab.rb', line 6

def grab &block
  @grabbed_output = ""
  class << self
    def write arg
      @grabbed_output += arg
    end
  end

  begin
    yield
  ensure
    singleton_class.send :remove_method, :write
  end

  @grabbed_output
end