From: Sean Chittenden Date: 2002-05-14T04:48:57+09:00 Subject: Re: cgi params api > > So then the question is: what's a special case of a multi-value > > array in Ruby? A one-value array, or a string? Answer: it depends on the context. I think the one saving grace from Perl is the wantarray() function. > Here's the CGI params: > > foo=bar&quux=one&quux=two&quux=three apr = Http::Param.new(r) # I really dislike the name CGI apr['foo'].inspect # 'bar' apr['foo'].type # String apr['quux'].inspect # ['one','two','three'] apr['quux'].type # Http::Param::Array And the questionable behavior. apr['quux'].to_s # 'one' or: apr['quux'].to_s # raises an exception until defined by # the developer I'm leaning toward the former. What do you guys think? No matter what, there's going to have to be some code that will test for single vs. multiple values. The catch here is, however, that in 99% of the cases, if the developer wants one element, they're going to get one element back in the form of a string. If they want one or more, they're going to write their code to handle more than one. The above fits nicely into the POLS. Because a String object has a to_a() method, it's safe for the folks who want bullet proof code to write the following: for i in apr['quux'].to_a # do whatever end Are there any scenarios that would fail badly with the above? -sc -- Sean Chittenden