Class: Gem::Commands::NewCommand::StringReplacer

Inherits:
Object
  • Object
show all
Defined in:
lib/gem/commands/new_command/string_replacer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(variables) ⇒ StringReplacer

Returns a new instance of StringReplacer.



9
10
11
12
# File 'lib/gem/commands/new_command/string_replacer.rb', line 9

def initialize(variables)
  @variables = Hash[variables.map { |k,v| [k.to_s, v.to_s] }] # convert keys and values to strings
  @pattern   = Regexp.union(@variables.keys.map { |var| Regexp.escape(var) })
end

Class Method Details

.replace(string, variables) ⇒ Object



5
6
7
# File 'lib/gem/commands/new_command/string_replacer.rb', line 5

def self.replace(string, variables)
  new(variables).replace(string)
end