Last active
August 29, 2015 13:55
-
-
Save LFDM/8721142 to your computer and use it in GitHub Desktop.
Demo of ternary splitjoin implementation
This file contains hidden or 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
# Ternary splitjoin | |
condition ? 'this' : 'that' | |
# split | |
if condition | |
'this' | |
else | |
'that' | |
end | |
# join | |
condition ? 'this' : 'that' | |
########### | |
unless condition | |
x = 'a' | |
else | |
y = 'b' | |
end | |
#join | |
condition ? y = 'b' : x = 'a' | |
# split | |
if condition | |
y = 'b' | |
else | |
x = 'a' | |
end | |
########### | |
if condition | |
x = 'a' | |
else | |
x = 'b' | |
end | |
# join | |
x = (condition ? 'a' : 'b') | |
# split | |
x = if condition | |
'a' | |
else | |
'b' | |
end | |
########### | |
x = if condition | |
'a' | |
else | |
'b' | |
end | |
#join | |
x = (condition ? 'a' : 'b') | |
# split | |
x = if condition | |
'a' | |
else | |
'b' | |
end | |
########### | |
# different formatting, some might prefer this | |
x = unless condition | |
'something' | |
else | |
'anything' | |
end | |
# join | |
x = (condition ? 'anything' : 'something') | |
# split | |
x = if condition | |
'anything' | |
else | |
'something' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment