The object itself. Inside a method, you can refer to the instance to which the method belongs with a pseudo-variable named self. This in other languages.
When a method call that omits the receiver is made in the method, self becomes the receiver. The receiver is often omitted when it can be omitted.
class Numbers
attr_accessor :number
def set_number
self.number = 30 #Put 30 when you call the number of this class
end
end
num1 = Numbers.new
num1.set_number
num1.number # => 30
Recommended Posts