From: Wakou Aoyama Date: 2003-02-08T05:34:41+09:00 Subject: Re: easy access for CGI query On Sat, Feb 08, 2003 at 04:28:02AM +0900, ahoward wrote: > http://messyquerystrings.com/%20key%20with%20spaces=value > > q.key_with_spaces perhaps?? > > http://messyquerystrings.com/%2fkey%2fwith%2fslashes=value > > q.key/with/slashes perhaps?? Oh! require "cgi" ENV['REQUEST_METHOD'] = 'GET' ENV['QUERY_STRING'] = 'key=value1&key%20with%20spaces=value2&key%2fwith%2fslashes=value3' class CGI class Query def initialize(params, substitute) @params = params @substitute = substitute end def method_missing(key) @params[@substitute[key.to_s] || key.to_s].first end end def query(substitute = {}) CGI::Query.new(@params, substitute) end end q = CGI.new.query("key_with_spaces" =>"key with spaces", "key_with_slashes"=>"key/with/slashes") # "ruby_name" => "cgi name" p q.key # ==> "value1" p q.key_with_spaces # ==> "value2" p q.key_with_slashes # ==> "value3" -- Wakou Aoyama