# Subclass IO

**URL:** <https://rubytalk.org/t/subclass-io/2344>\
**Category:** ruby-talk\
**Created:** [17 October 2002 11:25 UTC](https://rubytalk.org/t/subclass-io/2344 "2002-10-17T11:25:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Kogler](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Marco\_Kogler](https://rubytalk.org/u/Marco_Kogler)\
**Post date:** [17 October 2002 11:25 UTC](https://rubytalk.org/t/subclass-io/2344/1 "2002-10-17T11:25:15Z")

</div>

Hi!

I’m writing an application with a graphical (OpenGL) console, which is  
running a Ruby interpreter internally. Obviously, I want all the output  
that Ruby generates to be displayed in my graphics console. Now, I found  
some piece of code using $defout to redirect the output done by print,  
puts, etc…

So, I thought, I would be able to achieve this, if I implement my own IO  
subclass, which I can then assign to $defout. Could anyone point me to  
some information telling me what methods to implement for a working IO  
subclass?

Thanks,  
Marco

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [17 October 2002 12:04 UTC](https://rubytalk.org/t/subclass-io/2344/2 "2002-10-17T12:04:27Z")

</div>

Hi,

> **···**
>
> At Thu, 17 Oct 2002 20:25:15 +0900, Marco Kögler wrote:
> 
> > So, I thought, I would be able to achieve this, if I implement my own  
> > IO subclass, which I can then assign to $defout. Could anyone point me  
> > to some information telling me what methods to implement for a working  
> > IO subclass?
> 
> $defout needs “write” method.
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Gavin\_Sinclair](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Gavin\_Sinclair](https://rubytalk.org/u/Gavin_Sinclair)\
**Post date:** [17 October 2002 12:13 UTC](https://rubytalk.org/t/subclass-io/2344/3 "2002-10-17T12:13:44Z")

</div>

> Hi!
> 
> I’m writing an application with a graphical (OpenGL) console, which is  
> running a Ruby interpreter internally. Obviously, I want all the output  
> that Ruby generates to be displayed in my graphics console. Now, I found  
> some piece of code using $defout to redirect the output done by print,  
> puts, etc…
> 
> So, I thought, I would be able to achieve this, if I implement my own IO  
> subclass, which I can then assign to $defout. Could anyone point me to  
> some information telling me what methods to implement for a working IO  
> subclass?
> 
> Thanks,  
> Marco

You may not need to subclass IO. Just create a class or object that implements  
:puts, and see if that works. If you get error messages about missing methods,  
implement them.

If you want to know what methods are in IO, download ‘ri’ and run ‘ri IO’.

Cheers,  
Gavin

> **···**
>
> From: “Marco Kögler” [marco.koegler@web.de](mailto:marco.koegler@web.de)
