On 2002.05.13, David Alan Black <dblack / candle.superlink.net> wrote: > > I'm saying that 'val1' == 'val1' and that 'val1'.to_a == ['val1'] > > and ['val1', 'val2'].to_a == ['val1', 'val2']. The only "strange" > > behavior I'm suggesting is: > > > > ['val1', 'val2'].to_s == 'val1' > > > > Well, not #to_s, but #[] of the cgi class, in this case. > > OK... you said, given a case where there are two values: > > > p['name'] always returns val1. p['name'].to_a returns the array of > > values. > > So, if p['name'] returns 'val1', then the object on which you're > calling #to_a to is 'val1'. The #[] method doesn't know that #to_a is > going to be called on its return value. It's like: > > res = p['name'] # => 'val1' > res.to_a # => ['val1','val2'] > > Hence my thought that: > > > > It's like saying: 'val1'.to_a == ['val1', 'val2'] > > Now, it may not exactly be a String that p['name'] returns -- in fact, > I think it would have to be an object that somehow stored the other > array elements, so that if #to_a is called on it, it can restore > them. At that point, in addition to at least the "feel" of #to_a > behaving too magically, I start to wonder why not just make the array > elements clearly visible in the first place. Ah, I see the problem now. p['name'] would return some kind of subclass of Array whose #to_s method was implemented to return just the first element in the array. So, p['name'] always returns this new subclass. It's #to_a method returns an array of values, while its #to_s method just returns the first value. Does this make sense? Is this useful? -- 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)