Skip to content

Instantly share code, notes, and snippets.

@LFDM
Last active August 29, 2015 13:55
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 LFDM/8721142 to your computer and use it in GitHub Desktop.
Save LFDM/8721142 to your computer and use it in GitHub Desktop.
Demo of ternary splitjoin implementation
# 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