On Fri, May 30, 2003 at 08:48:04PM +0900, Martin DeMello wrote:
> Ian Macdonald <ian / caliban.org> wrote:
> > 
> > I'm trying to replace every instance of ' with \' but it's proving very
> > tricky. Nothing I can come up with seems to work, no matter how many
> > backslashes I use, whether I use single or double quotes, whether or not
> > I use gsub with a block, etc.
> > 
> > This should be so easy, but it has me stumped.
> 
> foo = "'123"
> puts foo.gsub(/'/) {'\\'+"'"}
> 
> I find it more readable than the multiply-self-escaping string of
> backslashes.

But '\\' and "\\" are the same thing (a single backslash)

   puts '\\'.size   #>> 1
   puts "\\".size   #>> 1

So concatenating two strings like that doesn't help you at all.

Regards,

Brian.