On 2002.05.14, Sean Chittenden <sean / ruby-lang.org> wrote: > > > 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. Yes! This is definitely wantarray envy. I've just spent the last hour trying to implement what I've been talking about, and have realized that the behavior I wanted isn't possible in Ruby without knowing what the desired return type is. > > 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've finally implemented code that makes these tests pass given the params I listed earlier: cgi['abc'].type # => NilClass cgi['foo'].type == CGI::Param # => true cgi['foo'] == "bar" # => true cgi['foo'].to_s == "bar" # => true cgi['foo'].to_a == ["bar"] # => true cgi['quux'].type == CGI::Param # => true cgi['quux'] == "one" # => true cgi['quux'].to_s == "one" # => true cgi['quux'].to_a == ["one", "two", "three"] # => true Hint: CGI::Param is a subclass of String, not Array. -- 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)