Gsub can't add a single backslash?

I want to escape a string such that all occurances of ‘&’ become ‘&’.

I can’t seem to do it with gsub.

irb(main):014:0> ‘&’.gsub(/&/, “&”)
"&“
irb(main):015:0> ‘&’.gsub(/&/, “\&”)
”&“
irb(main):016:0> ‘&’.gsub(/&/, “\&”)
”&“
irb(main):017:0> ‘&’.gsub(/&/, “\\&”)
”\&"

Have I stumbled upon a bug? It refuses to add a single backslash;
always zero or two.

Never mind, I was just reading it wrong. “\&” is actually ‘&’; it’s
just the way irb displays strings.

···

On Sat, Sep 28, 2002 at 04:54:55PM -0400, Philip Mak wrote:

irb(main):016:0> ‘&’.gsub(/&/, “\&”)
“&”
irb(main):017:0> ‘&’.gsub(/&/, “\\&”)
“\&”

Have I stumbled upon a bug? It refuses to add a single backslash;
always zero or two.