Method: Pkg::Util::Misc.search_and_replace
- Defined in:
- lib/packaging/util/misc.rb
.search_and_replace(search_string, replacements) ⇒ Object
This method takes a string and a list of tokens and variables and it replaces the listed tokens with the matched variable if it exists. All values will be explicitly coerced to strings.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/packaging/util/misc.rb', line 9 def search_and_replace(search_string, replacements) raise ArgumentError "replacements must respond to #each_pair" unless replacements.respond_to? :each_pair replacements.each_pair do |token, value| unless value warn "replacement value for '#{token}' probably shouldn't be nil" next end search_string.gsub!(token.to_s, value.to_s) end search_string end |