From: Daniel Carrera Date: 2002-11-26T15:15:03+09:00 Subject: Re: Difference between puts and print > Whereas if you try the following: > ------------------------------------------------------------ > p var > ------------------------------------------------------------ > it prints: > # > > Is there a way to override this behavior? So you could put > something different much like the array or hash printout with > the #p method? class Foo def inspect "Just override 'inspect'" end end p var # -> "Just override 'inspect'" Notice that I didn't have to do a 'var Foo.new' again. var was already a Foo, so when I modified Foo, var was changed correspondigly. > > --Andrew > > > > ------------------------------------------------------------ > > > #to_s | calls the 'stringify method' which prints > > > | a pretty version of the string (such as > > > | a way to print arrays in a meaningful way > > > | to a human) > > > > This one is cool. > > > > class Foo > > def initialize > > @var = "bar" > > end > > def to_s > > "This is a customized string" > > end > > end > > > > var = Foo.new > > > > puts var > > > > Prints out: > > "This is a customized string" > > > >