Skip to content

Instantly share code, notes, and snippets.

@stefanoc
Created July 19, 2011 12:42
Show Gist options
  • Save stefanoc/1092167 to your computer and use it in GitHub Desktop.
Save stefanoc/1092167 to your computer and use it in GitHub Desktop.
Compact if/else expression
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