Created
November 30, 2012 17:05
-
-
Save sd/4177024 to your computer and use it in GitHub Desktop.
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
x = "123" | |
case x | |
when /\d+/ | |
... | |
when String | |
... | |
when 1..3 | |
... | |
when "123" | |
... | |
end | |
# is equivalent to | |
if (/\d+/.=== x) | |
... | |
elsif (String.=== x) | |
... | |
elsif (1..3.=== x) | |
... | |
elsif ("123".=== x) | |
... | |
end | |
each class defines === in a way that makes sense... regexps try to match, classes check for the class of the object, ranges check for inclusion, strings check for equality, etc... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
that's a powerful case/switch statement, Java is missing out on that (i think they made it slightly better for Java 7), also we're missing out on operator overloading. It's pretty cool you can be so expressive with Ruby.