From: Gennady Date: 2003-06-13T08:31:13+09:00 Subject: Re: Confused about to_s in Ruby / irb Actually, irb uses "inspect" in this case. Gennady. ----- Original Message ----- From: "you CAN teach an old dog ..." Newsgroups: comp.lang.ruby To: "ruby-talk ML" 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) > # # ignores to_s > >