From: Arlen Cuss Date: 2008-02-22T08:20:07+09:00 Subject: Re: Kernel#putc vs. $stdout#putc ------=_Part_6306_28992168.1203636013515 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, On Fri, Feb 22, 2008 at 5:52 AM, Gordon Thiesfeld wrote: > OK, here's why I'm confused. In the code below, why isn't the output > of both of the putc methods 42? Here's the relevant code from io.c: static VALUE rb_io_putc(VALUE io, VALUE ch) { char c = NUM2CHR(ch); rb_io_write(io, rb_str_new(&c, 1)); return ch; } static VALUE rb_f_putc(VALUE recv, VALUE ch) { return rb_io_putc(rb_stdout, ch); } As you can see, rb_f_putc (Kernel.putc) is hard-wired to rb_io_putc (IO#putc) - but it's directly hard-wired (I believe), not literally as "$stdout.putc" but rather going straight to the function as defined here. This means that the two functions are 'identical' in nature -- Kernel.putcisn't $stdout.putc, but rather will always call rb_io_write(rb_stdout, rb_str_new(&ch, 1)), which is $stdout.write with a string of that one character. Hence, you actually would have to redefine both ($stdout.putc, by your ChunkyIO, *and* Kernel.putc) -- or redefine $stdout.write (in which case both functions will be affected) -- in order to get the effect you want. Cheers, Arlen. ------=_Part_6306_28992168.1203636013515--