Skip to content

Instantly share code, notes, and snippets.

@tastycode
Created September 9, 2012 16:22
Show Gist options
  • Save tastycode/3685411 to your computer and use it in GitHub Desktop.
Save tastycode/3685411 to your computer and use it in GitHub Desktop.
blog_snips
require 'english'
main_path = %r{/status/(?<code>\d+)}
format_path = %r{#{main_path}\.?(?<format>html|json)}
format_path =~ "/status/500.json"
$LAST_MATCH_INFO[:code] # => "500"
$LAST_MATCH_INFO[:format] # => "json"
matches = format_path.match "/status/500.json"
matches[:code] # => "500"
matches[:format] # => "json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment