Adding Functionality

suggest change

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) # => 8
6.concat_one # => '61'

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents