Skip to content

Instantly share code, notes, and snippets.

@DNA
Created September 12, 2020 15:41
Show Gist options
  • Save DNA/efc41f991c78580ead4989156799c101 to your computer and use it in GitHub Desktop.
Save DNA/efc41f991c78580ead4989156799c101 to your computer and use it in GitHub Desktop.
simple example for ruby pattern matching
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