On 2/21/07, Greg Hurrell <greg.hurrell / gmail.com> wrote:
> This instance method added to the String class returns a copy of the
> receiver with occurrences of \ replaced with \\, and occurrences of '
> replaced with \':
>
> class String
>   def to_source_string
>     gsub(/(\\|')/, '\\\\\1')
>   end
> end

  class String
    def to_source_string
      gsub(/(\\|')/) { "\\#$1" }
    end
  end

-austin
-- 
Austin Ziegler * halostatue / gmail.com * http://www.halostatue.ca/
               * austin / halostatue.ca * http://www.halostatue.ca/feed/
               * austin / zieglers.ca