Skip to content

Instantly share code, notes, and snippets.

@ozgun
Created July 24, 2012 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozgun/3168547 to your computer and use it in GitHub Desktop.
Save ozgun/3168547 to your computer and use it in GitHub Desktop.
# 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