Last active
February 18, 2016 20:55
-
-
Save nocash/4d5d3d596476d4c84992 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 Basket | |
| def initialize | |
| # use private setter to initialize variable | |
| set_contents(:empty) | |
| end | |
| def fill_basket | |
| set_contents(:fruit) | |
| end | |
| private | |
| def set_contents(contents) | |
| @contents = contents | |
| 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
| class Basket | |
| def initialize | |
| # initialize variable directly | |
| @contents = :empty | |
| end | |
| def fill_basket | |
| set_contents(:fruit) | |
| end | |
| private | |
| def set_contents(contents) | |
| @contents = contents | |
| 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
| # don't bother with setter for simple variables | |
| class Basket | |
| def initialize | |
| @contents = :empty | |
| end | |
| def fill_basket | |
| @contents = :fruit | |
| end | |
| end |
smdern
commented
Feb 18, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment