I tried to replace “’” characters with “’” strings using gsub. What
happened instead was something completely different. Am I missing
something here?
(in irb)
irb(main):001:0> s = “a’b’”
=> “a’b’”
Unexpected result
irb(main):002:0> s.gsub(/’/, “\’”)
=> “ab’b”
Also with this
irb(main):003:0> s.gsub(/’/, ‘\’’)
=> “ab’b”
However this works
irb(main):004:0> s.gsub(/’/, “\x’”)
=> “a\x’b\x’”
“\’” is the same than $’, i.e. MatchData#post_match. For example
Now that makes more sense… I didn’t know that. After looking in the
documentation, I found this only in PickAxe book. I haven’t found it
neither in the 1.8 RDoc nor in the mentioned article.
Attached is a patch against 1.182.2.48 revision of string.c, that adds
these sequences to rdoc (shamelessly ripped from the pickaxe book).