« Recycling Palms as secondary LCD displays | Main | Civilization in Wine on Linux. How civilized. »

Ruby string escaping weirdness

Well, that's odd... (ruby 1.8.7)

irb(main):021:0> '\\' + 'x'
=> "\\x"
irb(main):022:0> "x".gsub("x",'\\' + 'x')
=> "\\x"
irb(main):023:0> '\\' + '&'
=> "\\&"
irb(main):024:0> "&".gsub("&",'\\' + '&')
=> "&"

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)