From: Leslie Viljoen Date: 2006-07-29T18:21:57+09:00 Subject: Re: Puts bypasses access restrictions on to_s? On 7/29/06, Paul Battley wrote: > On 28/07/06, Leslie Viljoen wrote: > > I read somewhere that "puts" calls "to_s" on an object to get a string > > representation and then displays that. This seems to be correct in my > > experience. > > > > My question is: how does puts bypass "private" restrictions to get the > > value of to_s? > > Interesting question. I had a look at the C source, and it uses > rb_funcall, which doesn't check private/protected, to call to_s. > > If you want to do the same thing, you can use this: > rs.__send__(:to_s) That seems wrong! Not that you can bypass access restrictions, which I think you can do in many languages, but that 'puts' does so. Though OTOH I'm sure there's a very good argument for 'puts' being high-speed.