Last active
October 3, 2020 08:42
-
-
Save SamirTalwar/1887769 to your computer and use it in GitHub Desktop.
Optional in Ruby, for https://monospacedmonologues.com/2012/02/the-beast/.
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
| module Optional | |
| def self.of value | |
| Of.new value | |
| end | |
| def self.absent | |
| Absent.new | |
| end | |
| private | |
| class Of | |
| def initialize value | |
| @value = value | |
| end | |
| def or defaultValue | |
| @value | |
| end | |
| end | |
| class Absent | |
| def or defaultValue | |
| defaultValue | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment