well, it dosen't really end up working that way. i never use kind_of? or
the like, because, like you said, i know what my cgi form contains. thus
i know whether to expect a scalar or array before hand from a given
parameter. but i can see how this might not always be the case. but one
way or the other you going to have to deal with the possibility of
multiple array elements. your example is fine if the page dosen't use
any duplicate input tags, as it deals with mutiple array elements by
eliimnating them --a subset of the cgi. but i often have duplicate input
tags, so it won't work for me.

besides perhaps just leaving it as it is and grabbing the [0] index when
you know you have a scalar, i think my suggestion is the best
alternative. i've thought about it a long time and have not been able to
think of a better solution.

~transami

On Tue, 2002-07-02 at 19:04, Dan Debertin wrote:
> Tom Sawyer writes:
> 
>  > 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.
> 
> Chances are you're going to know in advance if your form (or whatever)
> contains duplicate values. In these cases, why not be consistent and
> convert? [] returning a different kind of object under certain
> circumstances seems undesirable to me -- eventually I'm going to
> forget to invoke .kind_of? on the result.
> 
> Here's what I ended up doing to solve the same problem:
> 
> module CGIFeatures
>   # Extensions to CGI to make it act more like a hash.
>   def to_h
>     h = {}
>     # Obviously, this breaks duplicate CGI params. 
>     self.keys.each { |k| h[k] = self[k][0] }
>     h
>   end
> end
> 
> cgi = CGI.new
> cgi.extend(CGIFeatures)
> params_as_hash = cgi.to_h
> 
> 
> Dan
> --
> airboss / nodewarrior.org
> www.nodewarrior.org
> ignorami: n: 
> The art of folding problem users into representational shapes.
> 
>