I ran into a little problem with String#tr today. I wanted to do
str = ‘kame^hame^ha^’
But I got back an error about having a nil character class ([^]).
According to the docs: “Both strings may use the c1?c2 notation to
denote ranges of characters, and from_str may start with a ^, which
denotes all characters except those listed.”
So it’s trying to interpret the first argument as some sort of a
single character regex, even though it’s in a string. Bummer. How then
can I replace a carat character in my string?
str.tr(’^’,’-’) doesn’t seem to work either.
Is there any way of doing this? I know that I can just use gsub
instead and go on with my life (I have actually), but this is
bothering me for some reason.