I have a question about what the best way is to reference a class variable in Ruby.
Here is a class I made:
class Person
attr_accessor :name
def initialize(name)
@name = name
end
def say_name
puts @name
end
def say_name2
puts self.name
end
end
bob = Person.new("Bob")
bob.say_name
=> "Bob"
bob.say_name2
=> "Bob"
Both of the "say_name" methods seems to work as intended. Why use the @variable vs the self.variable??