Created
April 2, 2012 16:30
-
-
Save jsanders/2284806 to your computer and use it in GitHub Desktop.
Prettier (?) elsif
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
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 |
So it does true === (true == false)
?
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) :)
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
Came across this Go idiom that I had never actually used in Ruby, but seemed like it would work just as well. Has everyone been using this already and I just missed the boat?