Created
April 7, 2015 14:46
-
-
Save trekdemo/7dd3cff9d1b5db09ac88 to your computer and use it in GitHub Desktop.
How to mimic fall through with ruby
This file contains 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
# Usage: | |
# foo('Near the intersection of Lexington Ave and E 40th St') | |
# # => ['Lexington Ave', 'E 40th St'] | |
# foo('Between Lexington Ave and E 40th St') | |
# # => ['Lexington Ave', 'E 40th St'] | |
# | |
def foo(value) | |
case value | |
when (re = /^Near the intersection of (.*) and (.*)$/) | |
when (re = /^Between (.*) and (.*)$/) | |
end | |
value.scan(re).flatten | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment