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.new => #<A:0x2ea606c @string='my string'> irb(main):010:0> puts a my string #<A:0x2ea606c> => 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
Thanks,
RM
You want your to_s method to just return @string, not do
puts @string.