Created
April 2, 2012 16:30
-
-
Save jsanders/2284806 to your computer and use it in GitHub Desktop.
Prettier (?) elsif
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
puts case true | |
when true == false | |
"nope" | |
when false == true | |
"also nope" | |
when [ :a ].empty? | |
"nope as well" | |
when nil.nil? | |
"yep!" | |
when false.nil? | |
"nopers" | |
else | |
"uh-uh" | |
end |
Honestly I think the reason it isn't an idiom in ruby is that elsif
strings read just as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, which raises an interesting point - where if/elsif tests the truthiness of its parameter, this actually tests against the
true
singleton versus anything else. So don't use it with.xhr?
(rails/rails#5329) :)