Created
April 29, 2012 03:16
-
-
Save ClayShentrup/2528600 to your computer and use it in GitHub Desktop.
Devil's advocate argument for having the case statement in Ruby
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
case some_value | |
when 1..10 | |
"do some stuff here" | |
when 11..20 | |
"do something else here" | |
else | |
"out of range" | |
end | |
# compared to | |
if 1..10.include?(some_value) | |
"do some stuff here" | |
elsif 11..20.include?(some_value) | |
"do something else here" | |
else | |
"out of range" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment