Actually, irb uses "inspect" in this case. Gennady. ----- Original Message ----- From: "you CAN teach an old dog ..." <itsme213 / hotmail.com> Newsgroups: comp.lang.ruby To: "ruby-talk ML" <ruby-talk / ruby-lang.org> Sent: Thursday, June 12, 2003 4:26 PM Subject: Confused about to_s in Ruby / irb > I wish to control the default display of my objects, and thought to_s > would be the right hook. But ruby (at least irb) seems to use my to_s > only if the class has no instance variables. Am I doing something > wrong? > > What other display-related hooks are there? > > Thanks > > irb> class A > irb> def to_s > irb> "an A" > irb> end > irb> end > nil > > irb> A.new > an A # uses to_s > > irb> class B > irb> def initialize(x) > irb> @x = x > irb> end > irb> def to_s > irb> "a B" > irb> end > irb> end > nil > > irb> B.new (5) > #<B:0x2a51b98 @x=5> # ignores to_s > >