redefine basic arithmetic : Fixnum extension « Number « Ruby






redefine basic arithmetic


class Fixnum 
    alias old_plus + 
    # Redefine addition of Fixnums. This is a BAD IDEA! 
    def +(other) 
        old_plus(other).succ 
    end 
end 

 








Related examples in the same category

1.Calculating a factorial in Ruby
2.Simulating a Subclass of Fixnum
3.NoMethodError: undefined method 'new' for Fixnum:Class
4.Add double_upto method to Fixnum