Method: String#substitute_env_vars

Defined in:
lib/core_ext/string.rb

#substitute_env_varsString

Replace dollar-curly braces, with the value of environment variable

Returns:

  • string with all environment variables replaced



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/core_ext/string.rb', line 34

def substitute_env_vars
  str = String.new(self)
  str.scan(/\$\{([A-Z][A-Z,0-9,_]*)\}/).uniq.each do |m|
    begin
      str.gsub!("${#{m[0]}}", ENV[m[0]])
    rescue
      $stderr.puts "problem with enviroment variable #{m[0]}."
    end
  end
  str
end