Skip to content

Instantly share code, notes, and snippets.

@carlosramireziii
Created September 27, 2017 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosramireziii/7f5c5d6a6f22dfba36dd38d3d2b13c5d to your computer and use it in GitHub Desktop.
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
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