On Sun, Sep 22, 2002 at 03:34:39PM +0900, Philip Mak wrote:
> NameError: private method `gsub' called for [1, 2, 3]:Array
>         from /usr/local/lib/ruby/1.6/cgi.rb:260:in `escapeHTML'
>         from (irb):7

This is another way of saying that Array doesn't have a gsub method.
There is a gsub method in the Kernel module; all methods in the Kernel
module are mixed in to Object as private methods, hence this error
message.

The author could, as you suggested, have enforced that the object be a
String by raising an exception if it were not a String.  With this
particular function, I can't see anyone wanting to pass in anything
other than a String.  But since the method should work with any object
that has a gsub method that works like String's gsub method, there isn't
any reason to necessarily limit the method to only Strings.

If I had added a gsub method to the Array object I passed in, then this
might have worked.  I'm not sure what gsub on an Array would do, but it
might make sense for other types of objects.

The author could also have uesd to_s or to_str to coerce the object that
was passed in into the type of object that he wanted.

Paul