On Wednesday 20 August 2008, Nick Brown wrote: > So the problem doesn't seem to be with sub! at all. It's with cgi. > > If I get the variable "a" using the cgi code above, then I create string > "b": > > a = cgi['a'] > b = String.new > > a.class > => String > b.class > => String > > So they should have the same methods since they are the same class. > However, "a" seems to have extra methods. > a.first > => "hi" > b.first > NoMethodError: undefined method `first' for "":String > > > It seems the cgi object is returning strings that aren't really strings. > If that's the case, isn't it a bug that cgi['a'].class returns "String" > when it is really something else? The string returned by Cgi#[] are extended by the CGI::QueryExtension::Value module, which is an intentionally undocumented module defined in cgi.rb and adds methods like to_ary, first and last and modifies others (like []). I don't know whether this is documented or not, since I've never used this library. This fact, however, doesn't explain (at least I don't think so) the weird behaviors which have been reported in this thread. Stefano