Skip to content

Instantly share code, notes, and snippets.

@nedzadarek
Created December 17, 2014 18:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nedzadarek/0f9f99755d42bad10c30 to your computer and use it in GitHub Desktop.
if vs ternary operator(?)
# 1
# you have to use parens => `()`
# otherwise Ruby will threat it as `stuff if condition`
puts (if 1
then 2
else 3
end)
# 2
puts 1 \
? 2 \
: 3
# 3
# we are repeating word: puts
if 1 then
puts 2
else
puts 3
end
# 4
# we are using variable
# we won't use that variable (a) again
a = if 1 then
2
else
3
end
puts a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment