instance method
capture
Ruby on Rails 3.2.22.5
Since v3.1.12 Last seen in v4.2.9Signature
capture(stream)
Captures the given stream and returns it:
stream = capture(:stdout) { puts "Cool" } stream # => "Cool\n"
Parameters
-
streamreq
Source
# File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 70
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
Defined in activesupport/lib/active_support/core_ext/kernel/reporting.rb line 70
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Kernel