hello,
require "cgi"
q = CGI.new.query
p q.key # ==> “value”
How about this?
···
class CGI
class Query
def initialize(params)
@params = params
end
def method_missing(key)
@params[key.to_s].first
end
end
def query
CGI::Query.new(@params)
end
end
cgi = CGI.new
q = cgi.query
p q.key # ==> “value”
–
Wakou Aoyama wakou@ruby-lang.org
hello,
require “cgi”
q = CGI.new.query
p q.key # ==> “value”
How about this?
http://messyquerystrings.com/%20key%20with%20spaces=value
??
q.key_with_spaces perhaps??
http://messyquerystrings.com/%2Fkey%2Fwith%2Fslashes=value
q.key/with/slashes perhaps??
??
how will those work as method names?
-a
···
On Sat, 8 Feb 2003, Wakou Aoyama wrote:
class CGI
class Query
def initialize(params)
@params = params
end
def method_missing(key)
@params[key.to_s].first
end
end
def query
CGI::Query.new(@params)
end
end
cgi = CGI.new
q = cgi.query
p q.key # ==> “value”
–
====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
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”
···
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??
–
Wakou Aoyama wakou@ruby-lang.org
It’s ok.
cgi = CGI.new
cgi.query.params # == cgi[‘params’]
q = CGI.new.query
q.params
···
On Sat, Feb 08, 2003 at 05:14:37AM +0900, Eric Hodel wrote:
require “cgi”
q = CGI.new.query
p q.key # ==> “value”
–
Wakou Aoyama wakou@ruby-lang.org
Hello, again.
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] || key.to_s].first
end
end
def query(substitute = {})
CGI::Query.new(@params, substitute)
end
end
q = CGI.new.query
p q.key # ==> "value1"
p q.key_with_spaces # ==> nil
p q.key_with_slashes # ==> nil
q = CGI.new.query(
:ruby_name => “cgi name”,
:key_with_spaces => “key with spaces”,
:key_with_slashes => “key/with/slashes”
)
p q.key # ==> "value1"
p q.key_with_spaces # ==> "value2"
p q.key_with_slashes # ==> “value3”
···
–
Wakou Aoyama wakou@ruby-lang.org
But still magic and can be confusing, it smells of PHP’s register_globals
evilness.
···
Wakou Aoyama (wakou@ruby-lang.org) wrote:
On Sat, Feb 08, 2003 at 05:14:37AM +0900, > Eric Hodel wrote:
It’s ok.
cgi = CGI.new
cgi.query.params # == cgi[‘params’]
q = CGI.new.query
q.params
–
Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
Yes, therefore This plan is not use globals and not pollute other
scopes.
How about this as additional way?
···
On Sat, Feb 08, 2003 at 06:08:48AM +0900, Eric Hodel wrote:
But still magic and can be confusing, it smells of PHP’s register_globals
evilness.
–
Wakou Aoyama wakou@ruby-lang.org
in PHP, it polutues the global namespace, here it polutes the CGI
namespace, I don’t think that’s much of a tradeoff, especially when
cgi.params[‘foo’] works just as well. I just don’t like it in the
standard library, as it can cause too many surprises, and doesn’t feel
right.
···
Wakou Aoyama (wakou@ruby-lang.org) wrote:
On Sat, Feb 08, 2003 at 06:08:48AM +0900, > Eric Hodel wrote:
But still magic and can be confusing, it smells of PHP’s register_globals
evilness.
Yes, therefore This plan is not use globals and not pollute other
scopes.
How about this as additional way?
–
Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
Hi,
“params” is OK, but “print” does not work, since “method_missing” will
not be called for defined methods.
?? It’s work. CGI.new.query is a CGI::Query object. Not a CGI object.
Every object has private “print” method.
and, I don’t like method_missing. If use method override then q.id is
work, too. But, there is a problem. q.id is not return Object#id.
(return cgi[‘id’])
This is my point.
matz.
···
In message “Re: easy access for CGI query” on 03/02/08, Wakou Aoyama wakou@ruby-lang.org writes:
No, it not polutes the CGI namespace.
cgi.params[‘foo’]
cgi.params[‘bar’]
cgi.params[‘baz’]
cgi.query.foo
cgi.query.bar
cgi.query.baz
humm… It’s maybe not suprise, bat surplus?
···
On Sat, Feb 08, 2003 at 06:52:40AM +0900, Eric Hodel wrote:
in PHP, it polutues the global namespace, here it polutes the CGI
namespace, I don’t think that’s much of a tradeoff, especially when
cgi.params[‘foo’] works just as well. I just don’t like it in the
standard library, as it can cause too many surprises, and doesn’t feel
right.
–
Wakou Aoyama wakou@ruby-lang.org
→ humm… It’s maybe not surprise, but surplus?
and, Is not there a supporter?
···
On Sat, Feb 08, 2003 at 08:01:26AM +0900, Wakou Aoyama wrote:
humm… It’s maybe not suprise, bat surplus?
–
Wakou Aoyama wakou@ruby-lang.org