Created
September 12, 2020 15:41
-
-
Save DNA/efc41f991c78580ead4989156799c101 to your computer and use it in GitHub Desktop.
simple example for ruby pattern matching
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
def beach(*temperature) | |
case temperature | |
in :celcius | :c, (20..45) | |
:favorable | |
in :kelvin | :k, (293..318) | |
:scientifically_favorable | |
in :fahrenheit | :f, (68..113) | |
:favorable_in_us | |
else | |
:avoid_beach | |
end | |
end | |
beach(:c, 40) # :favorable | |
beach(:k, 300) # :scientifically_favorable | |
beach(300) # :avoid_beach |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment