From: "Iñaki Baz Castillo" Date: 2009-03-31T06:53:35+09:00 Subject: Re: Which methods does "puts" invoke? El Lunes 30 Marzo 2009, Eric Jacoboni escribió: > Iñaki Baz Castillo writes: > > Hi, if I redefine "to_s" or "inspect" methods in String class I still get > > the original output when doing: > > > > puts string > > > > Which String@method is invoked when executing "puts"? > > to_s (inspect is called by p) > > >> class Truc > >> end > > => nil > > >> machin = Truc.new > > => # > > >> puts machin > > # > => nil > > >> class Truc > >> def to_s > >> "to_s called" > >> end > >> end > > => nil > > >> puts machin > > to_s called > => nil Well, I already tested it, and yes, it seems to work if you define to_s method in some custom class, but note the following: -------- class String def to_s "hiiiiiii" end end # s=String.new("qweqwe") # puts s qweqwe nil ----------- ¿? -- Iñaki Baz Castillo