Last active
December 25, 2015 15:59
-
-
Save coderdan/7002278 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_writer :job | |
| def job | |
| @job || NoJob.new | |
| end | |
| end | |
| class Job | |
| def title | |
| "CEO" | |
| end | |
| end | |
| class NoJob | |
| def title | |
| raise "Person is unemployed" | |
| end | |
| end | |
| frank = Person.new | |
| frank.job = Job.new | |
| frank.job.title => "CEO" | |
| bum = Person.new | |
| bum.job.title => raises "Person is unemployed" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment