Ruby object printing format

Consider the following:

irb(main):001:0> class A
irb(main):002:1> def initialize
irb(main):003:2> @string = "my string"
irb(main):004:2> end
irb(main):005:1> def to_s
irb(main):006:2> puts @string
irb(main):007:2> end
irb(main):008:1> end
=> nil
irb(main):009:0> a =
=> #<A:0x2ea606c @string="my string">
irb(main):010:0> puts a
my string
=> nil

When 'puts' outputs the string my does it also append the refference of the object ?

Is there anyway to get rid of this behavior? What I want outputed is justs the string @string as defined in the classes 'to_s' method




You want your to_s method to just return @string, not do puts @string.

Need Your Help

How does the tooltip control enhance all controls on the form with a new property? winforms components

When answering another question I started to wonder how I could Add new properties to all controls in a form just like the ToolTip-control does.