How can't i modify the to_s method in Integer Class?

class Integer

def to_s
‘9’
end

end

puts 5.to_s

I’m still getting 5.

Grab Mail wrote:

I’m still getting 5.
There’s also the gotcha of redefining core methods - other core methods
just might call directly their implementations in C without going
through the interpreter.

Try not to rely on core method redefining unless you know you’ll always
be calling the redefined methods directly.

David V.

You shoud use Fixnum class instead of Integer.

Grab Mail wrote:

I’m still getting 5.

#to_s is defined in Fixnum, a subclass of Integer. Try this:

class Fixnum
def to_s
‘9’
end

end

puts 5.to_s