Method: String#tr!
- Defined in:
- lib/jcode.rb
#tr!(from, to) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/jcode.rb', line 133 def tr!(from, to) return nil if from == "" return self.delete!(from) if to == "" pattern = TrPatternCache[from] ||= /[#{_regex_quote(from)}]/ if from[0] == ?^ last = /.$/.match(to)[0] self.gsub!(pattern, last) else h = HashCache[from + "1-0" + to] ||= (from, to) self.gsub!(pattern) do |c| h[c] end end end |