How do you do a global string substitution when the pattern string is given 
and may contain characters like $ * and so on?

For example, I'd like to do

  "foo $x baz".gsub('\\$x', 'bar')
  
*without* having to quote all the special symbols.

One way would be to use String#[]= and iterate, but there should be a 
single call to do this.

Question: why doesn't gsub distinguish between a string and a regexp in its 
first argument, whereas []= does?

s = "x$z"; s["$"] = "y"; s
 ==> "xyz"

s = "x$z"; s[/$/] = "y"; s
 ==> "x$zy"                                                                 
     
-- 

Joel VanderWerf
skeeler / sirius.com