Created
August 22, 2015 04:51
-
-
Save eternal44/d9a96d17dfa9759b83f3 to your computer and use it in GitHub Desktop.
Ternary substitute
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
# 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