From: Jean-Hugues ROBERT Date: 2002-05-09T19:23:45+09:00 Subject: Re: cgi params api On Thu, May 09, 2002 at 02:39:43PM +0900, Patrick May wrote: > > One thing that I don't like is the way cgi forces you to treat every > > param as if there were multiples, when most of the time you're dealing > > with single params. > > > > I know you can do things like > > > > multiple, = cgi["multiple"] > > > > or > > > > multiple = cgi["multiple"][0] > > > > but these seem crufty. Here's an idea I had: > > > > > > # query string => "multiple=something&key=value&multiple=somethingelse" > > cgi["multiple"] # <= "something" > > cgi["multiple"].multiple # <= ["something", "somethingelse"] > > > > cgi["key"] # <= "value" > > cgi["key"].multiple # <= ["value"] > > > > > > This api would handle the most common case in a very intuitive way for > > the programmer. It also allows the programmer to explicitly handle > > multiple params. That would be nice. However I don't understand how it works. Is there some kind of a possibility in Ruby to define a []multiple() method ? Looks to me that only cgi.multiple("multiple") can work. What am I missing ? I guess a trick could be: class CgiParamValues def initialize( values ) @v = values end def to_str() @v[0] end # Makes self look like a String for most purpose ? def multiple() @v end end But, then, cgi["multiple"] does not return a String any more, it returns a CgiParamValues. Another trick would be class String def multiple() $CGI_Cache[self] or [self] end end But, then, how/when do you clear the cache ? Yours, Jean-Hugues