Sha256: f66844984bcf85bded603971707a701a663e1ed21750a816c34ec1cf57878e5f
Contents?: true
Size: 485 Bytes
Versions: 8
Compression:
Stored size: 485 Bytes
Contents
class String def gzub(regexp, format=nil, &proc) md = match(regexp) raise "#{self.inspect} doesn't match #{regexp.inspect}" if md.nil? s = dup pos = 0 md.captures.each_with_index do |m, n| replacement = if block_given? proc.call(m) else format % m end if md.offset(n+1)[0] s[md.offset(n+1)[0] + pos, m.length] = replacement pos += replacement.length - m.length end end s end end
Version data entries
8 entries across 8 versions & 3 rubygems