Last active
December 15, 2015 04:04
-
-
Save YumaInaura/b827640b27ed02208aee to your computer and use it in GitHub Desktop.
Ruby | attr_accessor + initialize でアクセサ変数に代入できない時 ref: http://qiita.com/Yinaura/items/02c8bd7bd87cfa64ce6c
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 Book | |
| attr_accessor :price | |
| def initialize | |
| price = 1080 | |
| end | |
| end |
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
| book = Book.new | |
| p book.price | |
| # => nil |
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 Book | |
| attr_accessor :price | |
| def initialize | |
| self.price = 1080 | |
| end | |
| end |
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
| book = Book.new | |
| p book.price | |
| # => 1080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment