Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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