Omar Campos wrote:
Hi all,
Is there a way to redirect the standard output, so that command like
puts write to a file instead of the console?
Using this as a way to shamelessly promote my 'desc_method' gem...
$stdout.methods
=> [:reopen, :print, ...]
require 'desc_method'
=> true
$stdout.desc_method :reopen
sig: #<Method: IO#reopen> arity: -1
appears to be a c method
searching ri for IO#reopen...
-------------------------------------------------------------- IO#reopen
ios.reopen(other_IO) => ios
ios.reopen(path, mode_str) => ios
From Ruby 1.9.1
路路路
------------------------------------------------------------------------
Reassociates _ios_ with the I/O stream given in _other_IO_ or to a
new stream opened on _path_. This may dynamically change the actual
class of this stream.
f1 = File.new("testfile")
f2 = File.new("testfile")
f2.readlines[0] #=> "This is line one\n"
f2.reopen(f1) #=> #<File:testfile>
f2.readlines[0] #=> "This is line one\n"
(end ri)
=> "#<Method: IO#reopen>"
$stdout.reopen("abc", "w")
Enjoy
-r
--
Posted via http://www.ruby-forum.com/\.