-
-
Save jeffkreeftmeijer/99ac66a9665ae8cc6b12 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
# Option 1 | |
info = if publication | |
"Title: #{ publication.title } (ID: #{ publication.id })" | |
else | |
'N/A' | |
end | |
# Option 2 | |
info = case publication | |
when Publication then puts "Title: #{ publication.title } (ID: #{ publication.id })" | |
when nil then puts 'N/A' | |
end | |
# Option 3 (brevity) | |
info = publication ? "Title: #{ publication.title } (ID: #{ publication.id })" : 'N/A' | |
# Option 4 (readability) | |
if publication | |
info = "Title: #{ publication.title } (ID: #{ publication.id })" | |
else | |
info = 'N/A' | |
end |
chastell
commented
Dec 17, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment