Skip to content

Instantly share code, notes, and snippets.

@dbrady
Created February 26, 2011 04:48
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 dbrady/844950 to your computer and use it in GitHub Desktop.
Save dbrady/844950 to your computer and use it in GitHub Desktop.
Semantically identical code, three idiomatic ways of expressing it
# Coders from from C often like this style:
log status == OK ? "OK" : "PROBLEM"
log "All done."
# But since if returns a value in ruby, you can spell it out:
log if status == OK
"OK"
else
"PROBLEM"
end
log "All done."
# I favor this style, because it pushes the whole expression out and preserves the vertical registration of if/else/end
log if status == OK
"OK"
else
"PROBLEM"
end
log "All done."
@avdi
Copy link

avdi commented Feb 27, 2011

If we're still doing Ruby you don't need any of those semicolons:

puts(if status==OK then "OK" else "PROBLEM" end)

works just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment