Created
September 27, 2017 01:13
-
-
Save carlosramireziii/7f5c5d6a6f22dfba36dd38d3d2b13c5d to your computer and use it in GitHub Desktop.
Illustrating the need for using "self" when using a setter method within an instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
attr_accessor :name | |
def rename(new_name) | |
# creates a new local variable called `name` and sets its value to the variable `new_name` | |
name = new_name | |
# calls the `name=` method of the instance | |
self.name = new_name # | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment