Created
January 28, 2013 03:47
-
-
Save yangsu/4652864 to your computer and use it in GitHub Desktop.
Ruby Instance Variables
This file contains 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 :age | |
attr_reader :age | |
# gets translated into: | |
def age | |
@age | |
end | |
attr_writer :age | |
# gets translated into: | |
def age=(value) | |
@age = value | |
end | |
# attr_accessor :age gets will generate both of the methods above | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment