Source From Here
Question
This throws me a SystemStackError in 1.9.2 Ruby
but there is
no super for + (based on other errors). How can I access the original + functionality?
How-To
Use alias_method. Alias Fixnum's + to something else, then refer to it in the new +:
Supplement
* API:alias_method
Question
This throws me a SystemStackError in 1.9.2 Ruby
- class Fixnum
- def +(other)
- self + other * 2
- end
- end
How-To
Use alias_method. Alias Fixnum's + to something else, then refer to it in the new +:
- class Fixnum
- alias_method :old_add, :+
- def +(other)
- self.old_add(other) * 2
- end
- end
* API:alias_method
沒有留言:
張貼留言