Created
December 21, 2014 04:56
-
-
Save Jberlinsky/64e4cbeca33d65470120 to your computer and use it in GitHub Desktop.
Null Object Pattern Example
This file contains 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 NullNumber | |
def +(other) | |
raise ArgumentError | |
end | |
def to_i | |
raise ArgumentError | |
end | |
end | |
assert_nothing_raised do | |
1 + 1 | |
end | |
assert_raise ArgumentError do | |
NullNumber.new + 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment