Three beginner question:

1) Is this the best way to implement Perl's quotemeta in Ruby?

        def quotemeta(s)     
            s.gsub(/[^a-zA-Z_0-9]/) { "\\" + $& }
        end

   ...or should I extend the string class somehow?


2) Is there an equivalent to quotemeta already built in?


3) Ruby 1.4's CGI::escape is this:

  def CGI::escape(string)
    str = string.dup
    str.gsub!(/[^a-zA-Z0-9_.-]/n){ sprintf("%%%02X", $&.unpack("C")[0]) }
    str
  end

   Why not just this:

  def CGI::escape(string)
    string.gsub(/[^a-zA-Z0-9_.-]/n){ sprintf("%%%02X", $&.unpack("C")[0]) }
  end


Thanks!
-- 
matt