On 2002.05.15, David Alan Black <dblack / candle.superlink.net> 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 might agree to this: cgi["quux"].to_a # => [""] cgi["abc"].to_a # => [] Any arguments for or against either? -- Dossy -- Dossy Shiobara mail: dossy / panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)