Skip to content

Instantly share code, notes, and snippets.

@eternal44
Created August 22, 2015 04:51
Show Gist options
  • Save eternal44/d9a96d17dfa9759b83f3 to your computer and use it in GitHub Desktop.
Save eternal44/d9a96d17dfa9759b83f3 to your computer and use it in GitHub Desktop.
Ternary substitute
# doctest: get ternary equivalent when true
# >> ternary(3 > 1,"hello",3)
# => "hello"
# doctest: get ternary equivalent when false
# >> ternary(3 < 1,"hello",3)
# => 3
def ternary(statement, true_result, false_result)
(true_result if statement == true) ||
(false_result if statement == false)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment