Skip to content

Instantly share code, notes, and snippets.

@fedegl
Created January 15, 2013 03:04
Show Gist options
  • Save fedegl/4535690 to your computer and use it in GitHub Desktop.
Save fedegl/4535690 to your computer and use it in GitHub Desktop.
Descrifalo!
class FindReplacer < AbstractModifier
attr_reader :regexp, :replacement_rules
def initialize(original_value, replacement_rules={})
@original_value = original_value
@replacement_rules = replacement_rules
end
def modify
values = original_value.map do |value|
replaced = nil
replacement_rules.each do |regexp, substitute_value|
replaced = value.gsub!(regexp, substitute_value)
end
replaced.present? ? value : nil
end.compact
values
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment