Forum: Ruby $stdout changing?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
907f29cb608004d2156d5ce88240f09b?d=identicon&s=25 Tim Mcd (zonbi)
on 2009-03-10 01:37
Is it possible for me to have output that go to the $stdout go through a
method instead? ie:

Have stuff go through this:

def write_to(str)
  @socket.send(str, 0)
end

?
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2009-03-10 02:02
(Received via mailing list)
On Mar 9, 2009, at 17:35, Tim Mcd wrote:

> Is it possible for me to have output that go to the $stdout go
> through a
> method instead? ie:
>
> Have stuff go through this:
>
> def write_to(str)
>  @socket.send(str, 0)
> end

You can assign any object that responds to #write to $stdout.

See also:

http://blog.segment7.net/articles/2006/08/17/stdou...
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-03-10 10:29
(Received via mailing list)
2009/3/10 Eric Hodel <drbrain@segment7.net>:
>
> You can assign any object that responds to #write to $stdout.
>
> See also:
>
> http://blog.segment7.net/articles/2006/08/17/stdou...

In this case IO#reopen seems more appropriate IMHO (if it works with
Sockets, which I did not verify). It's faster (no Ruby code needed)
and will also work for sub processes.

Kind regards

robert
This topic is locked and can not be replied to.