I was playing with the last expression returned by the method,when it is being invoked via an object.
With the concept below code works.
class Simple
def foo
2 + 2
end
end
#=> nil
simple = Simple.new
#=> #<Simple:0x11eb390>
simple.foo
#=> 4
But why the below code returns such encoded value rather than 15
and 20
?
class Fixnum
def to_s
self + 5
end
end
#=> nil
puts 10
#<Fixnum:0x000015>
#=> nil
puts 15
#<Fixnum:0x00001f>
#=> nil
Can anyone help me here to understand the concept?
Edit:
class Fixnum
def to_s
self + 5
end
end
#=> nil
10.to_s
#=> #<Fixnum:0x000029>
Again the same result.