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