Created
July 23, 2015 09:13
-
-
Save yaodong/98c6758c967644d1b7c0 to your computer and use it in GitHub Desktop.
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 set_name | |
| @name = 'joe' | |
| end | |
| def dump_by_varibale | |
| puts @name | |
| end | |
| def dump_by_reader | |
| puts name | |
| end | |
| end | |
| a = Person.new | |
| a.set_name | |
| a.dump_by_varibale #=> "joe" | |
| a.dump_by_reader #=> "joe" | |
| puts a.name #=> "joe" | |
| # set by writer | |
| a.name = "john" | |
| a.dump_by_varibale #=> "john" | |
| a.dump_by_reader #=> "john" | |
| puts a.name #=> "john" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment