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.
Tim M. (Guest)
on 2009-03-10 02: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

?
Eric H. (Guest)
on 2009-03-10 03:02
(Received via mailing list)
On Mar 9, 2009, at 17:35, Tim M. 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...
Robert K. (Guest)
on 2009-03-10 11:29
(Received via mailing list)
2009/3/10 Eric H. <removed_email_address@domain.invalid>:
>
> 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.