Module: Kernel
- Defined in:
- lib/the_array_comparator/testing_helper.rb
Instance Method Summary collapse
-
#capture(stream) ⇒ Object
Captures the given stream and returns it:.
Instance Method Details
#capture(stream) ⇒ Object
Captures the given stream and returns it:
stream = capture(:stdout) { puts 'Cool' }
stream # => "Cool\n"
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/the_array_comparator/testing_helper.rb', line 43 def capture(stream) begin stream = stream.to_s eval "$#{stream} = StringIO.new" yield result = eval("$#{stream}").string ensure eval("$#{stream} = #{stream.upcase}") end result end |