From: khaines@... Date: 2006-07-29T07:33:08+09:00 Subject: Re: Puts bypasses access restrictions on to_s? On Sat, 29 Jul 2006, Leslie Viljoen wrote: > See here: > > irb(main):005:0> class RiseAndShine > irb(main):006:1> private > irb(main):007:1> def to_s > irb(main):008:2> "rising and shining" > irb(main):009:2> end > irb(main):010:1> end > => nil > irb(main):011:0> rs = RiseAndShine.new > => rising and shining > irb(main):012:0> rs.to_s > NoMethodError: private method `to_s' called for rising and > shining:RiseAndShine > from (irb):12 > irb(main):013:0> puts rs > rising and shining irb(main):008:0> rs.__send__(:to_s) => "rising and shining" Ruby lets private be circumvented. To see how puts really works, though, take a look at the source code. It's pretty easy to read. Look in io.c for rb_io_puts(). Start from there. Kirk Haines