I know it makes sense to use self.name, but what does @name mean in the following code?
class NewGame < Game
attr_accessor :name
def initialize(name, options={})
super
self.name = name
end
def add_game(name)
@name = name
end
end
Is that even legit? Did I made a mistake?
@nameis an instance variable which may be accessed like a private member of a class instance.self.nameis a method call on the self object, if it is not explicitly defined you will get a NoMethodError.I will go forward and explain that writing
attr_accessor :weightin your class is the same as: