Sha256: b28a745ad9ee25580c1fd10438c07140a5e353445081e58f5201e407d683fa3b
Contents?: true
Size: 640 Bytes
Versions: 10
Compression:
Stored size: 640 Bytes
Contents
class String # Apply a set of rules (regular expression matches) to the string. # # === Requirements: # The rules must be applied in order! So we cannot use a # hash because the ordering is not guaranteed! we use an # array instead. # # === Input: # The array containing rule-pairs (match, write). # # === Output: # The rewritten string. # # CREDIT: George Moschovitis def rewrite(rules) raise ArgumentError.new('The rules parameter is nil') unless rules rewritten_string = dup rules.each do |match,write| rewritten_string.gsub!(match,write) end return rewritten_string end end
Version data entries
10 entries across 10 versions & 1 rubygems