Last active
August 29, 2015 14:14
-
-
Save vargheseraphy/9007d6e141a442ea18a0 to your computer and use it in GitHub Desktop.
switch case in ruby
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
case a | |
when 1 | |
puts "Single value" | |
when 2, 3 | |
puts "One of comma-separated values" | |
when 4..6 | |
puts "One of 4, 5, 6" | |
when 7...9 | |
puts "One of 7, 8, but not 9" | |
when 1..4, 5 | |
puts "It's between 1 and 5" | |
else | |
puts "Any other thing" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/948135/how-can-i-write-a-switch-statement-in-ruby