Skip to content

Instantly share code, notes, and snippets.

@trekdemo
Created April 7, 2015 14:46
Show Gist options
  • Save trekdemo/7dd3cff9d1b5db09ac88 to your computer and use it in GitHub Desktop.
Save trekdemo/7dd3cff9d1b5db09ac88 to your computer and use it in GitHub Desktop.
How to mimic fall through with ruby
# 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