Skip to content

Instantly share code, notes, and snippets.

@jcsalterego
Created June 3, 2009 19:20
Show Gist options
  • Select an option

  • Save jcsalterego/123186 to your computer and use it in GitHub Desktop.

Select an option

Save jcsalterego/123186 to your computer and use it in GitHub Desktop.
#
# How do I extract a parameter from a URL in plain Ruby?
# "http://foo.com/bar.html?a=sdfas&b=xyz Want the value of parameter a.
# - http://twitter.com/mperham/status/2019870182
#
URL = "http://foo.com/bar.html?a=sdfas&b=xyz"
paramify = lambda url: dict([kv.split("=")
for kv
in url.split("?")[1].split("&")])
print paramify(URL)['a']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment