From: Tom Sawyer Date: 2002-07-03T09:51:02+09:00 Subject: Re: Getting CGI arguments as scalars you can also modify the CGI class to return a scalar if the parameters array only contains a sinlge element: require 'cgi' class CGI module QueryExtension def [](*args) if @params[*args] case @params[*args].length when 0 return nil when 1 return @params[*args][0] else return @params[*args] end else return nil end end end end as to the relative merits of this, which is better? i don't know. but this works well for me. the only trick is to remember to access the paramaters (i.e.cgi.params) directly if you want to manipulate the parameters array, as [] will no longer be certain to return such a reference. ~transami On Mon, 2002-07-01 at 14:29, Philip Mak wrote: > cgi = CGI.new > year = cgi['year'] => ['2002'] > > In the CGI module, all the arguments are given as arrays instead of > scalars (presumably to support the case where the HTML page had > multiple tags of the same name). > > How can I get it as a scalar, though? Right now I'm using: > > year ,= cgi['year'] > > Is this a safe syntax to use (i.e. will it be valid in future versions > of Ruby)? It seems to be an abuse of the comma notation (I would think > that the comma is meant to *separate* lvalues). >