Skip to content

Instantly share code, notes, and snippets.

@lucaschain
Created September 4, 2018 11:48
Show Gist options
  • Save lucaschain/f8b2d7928e3a89eed8c9b7cdeef29572 to your computer and use it in GitHub Desktop.
Save lucaschain/f8b2d7928e3a89eed8c9b7cdeef29572 to your computer and use it in GitHub Desktop.
Path splitting example in ruby
path = "api/auto/refinancing_empirica/result"
exp = /^api\/([a-z_]+)\/([a-z_]+)/
matched_params = exp.match(path) do |matches|
{
:product => matches[1].to_sym,
:modality => matches[2].to_sym
}
end
return if matched_params.nil?
params.merge!(matched_params)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment