Created
July 19, 2011 12:42
-
-
Save stefanoc/1092167 to your computer and use it in GitHub Desktop.
Compact if/else expression
This file contains 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
class TrueClass | |
def choose(if_true, if_false) | |
if_true | |
end | |
end | |
class FalseClass | |
def choose(if_true, if_false) | |
if_false | |
end | |
end | |
class NilClass | |
def choose(if_true, if_false) | |
if_false | |
end | |
end | |
a_string.blank?.choose("Is blank", "Is not blank") | |
render some_object.some_test?.choose("partial_a", "partial_b") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment