Instance variable: self vs @

Here is some code:

class Person
  def initialize(age)
    @age = age
  end

  def age
    @age
  end

  def age_difference_with(other_person)
    (self.age - other_person.age).abs
  end

  protected :age
end

What I want to know is the difference between using @age and self.age in age_difference_with method.

6 Answers
6

Leave a Comment