Instance Variables
Learn about instance variables.
Now that we’ve learned how the string that we pass to the new
method passes to the new object’s initialize
method, we can start improving initialize
. We want it to do something with the string and actually initialize our new object:
class Person
def initialize(name)
@name = name
end
end
This introduces a new type of variable called an instance variable. The @name
is what we call an instance variable. The @
symbol at the beginning of ...