Tutorial by Examples

You can add a method to any class in Ruby, whether it's a builtin or not. The calling object is referenced using self. class Fixnum def plus_one self + 1 end def plus(num) self + num end def concat_one self.to_s + '1' end end 1.plus_one # => 2 3.plus(5) ...

Page 1 of 1