From: David Alan Black Date: 2002-05-15T21:21:29+09:00 Subject: Re: cgi params api Hello -- On Wed, 15 May 2002, Dossy wrote: > On 2002.05.15, David Alan Black wrote: > > Hello -- > > > > On Wed, 15 May 2002, Dossy wrote: > > > > > OR, if you only want the single value regardless: > > > > > > ... do some stuff with cgi["key"][0] ... > > > > > > However, this gets dangerous if cgi["key"] has no values and > > > thus returns nil, NilClass#[] isn't defined, is it. So, > > > we have to guard references to cgi["key"][0] with cgi["key"].nil? > > > tests? Yuck. > > > > You could define your #[] to return an empty array instead of nil > > for non-existent keys. > > Given the parameters: foo=bar&quux= > > There's a big semantic difference between cgi["foo"], cgi["quux"] > and cgi["abc"]. > > cgi["foo"].to_a # => ["bar"] > cgi["quux"].to_a # => [] > cgi["abc"].to_a # => nil I was responding to the [0] point quoted above, specifically the concern that nil wouldn't respond to #[]. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav