lib/core/facets/string/rewrite.rb in facets-2.8.4 vs lib/core/facets/string/rewrite.rb in facets-2.9.0.pre.1
- old
+ new
@@ -1,25 +1,21 @@
class String
- # Apply a set of rules (regular expression matches) to the string.
+ # Apply a set of rules in the form of 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.
+ # * rules - The array containing rule-pairs (match, write).
#
- # === Input:
- # The array containing rule-pairs (match, write).
+ # Keep in mind that the order of rules is significant.
#
- # === Output:
- # The rewritten string.
+ # Returns 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|
+ rules.each do |(match,write)|
rewritten_string.gsub!(match,write)
end
return rewritten_string
end