Adriano Ferreira wrote:
> You're missing "to_s"
> 
> $ irb
> irb> class Foo; end
> => nil
> irb> Foo.new
> => #<Foo:0x1001380c>         <-- default stringification
> 
> irb> class Foo; def to_s; "a Foo"; end end
> => nil
> irb> Foo.new
> => a Foo                  <-- customized stringification
> 
> irb> quit

This is a little nit-picky, but this code won't actually work unless 
you've modified irb (as least it doesn't for me). As far as I know, irb 
evaluates each line and prints the result of calling the #inspect method 
on the return of the line. If we wanted to demonstrate the result of the 
new #to_s method, we would have to attempt to print our foo object, 
therefore implicitly calling #to_s. Like so:

irb(main):001:0> class Foo;end
=> nil
irb(main):002:0> myfoo = Foo.new
=> #<Foo:0x2829310>
irb(main):003:0> puts myfoo
#<Foo:0x2829310>
=> nil
irb(main):004:0> class Foo;def to_s;"hello from foo";end end
=> nil
irb(main):005:0> puts myfoo
hello from foo
=> nil

-- 
Posted via http://www.ruby-forum.com/.