Created
July 24, 2012 07:15
-
-
Save ozgun/3168547 to your computer and use it in GitHub Desktop.
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
# Not so good: | |
def street_name(user) | |
if user.address | |
user.address.street_name | |
else | |
'No street name on file' | |
end | |
end | |
# Better: | |
def street_name(user) | |
user.address.street_name | |
end | |
class User | |
def address | |
@address || NullAddress.new | |
end | |
end | |
class NullAddress | |
def street_name | |
'No street name on file' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment