Last active
December 28, 2015 06:58
-
-
Save sevenseacat/7460485 to your computer and use it in GitHub Desktop.
Alternatives for a full_name method
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 User | |
# Downsides - when first name is nil, you'll have a string like " LastName" | |
def full_name | |
"#{first_name} #{last_name}" | |
end | |
# Downsides - a bit harder to understand | |
def full_name | |
[first_name, last_name].compact.join(' ') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment