Sha256: eccec837579212a48b6888465ef57c231c932058b0394f834c156442b0a2a3f1

Contents?: true

Size: 642 Bytes

Versions: 7

Compression:

Stored size: 642 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

7 entries across 7 versions & 2 rubygems

Version Path
facets-2.4.0 lib/facets/string/rewrite.rb
facets-2.4.1 lib/facets/string/rewrite.rb
facets-2.4.2 lib/core/facets/string/rewrite.rb
facets-2.4.3 lib/core/facets/string/rewrite.rb
facets-2.4.4 lib/core/facets/string/rewrite.rb
facets-2.4.5 lib/core/facets/string/rewrite.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/string/rewrite.rb