Module: R10K::Util::Interp

Defined in:
lib/r10k/util/interp.rb

Instance Method Summary collapse

Instance Method Details

#interpolate_string(string, scope) ⇒ String

Interpolate a string with a given scope

Parameters:

  • string (String)
  • scope (Hash)

Returns:

  • (String)


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/r10k/util/interp.rb', line 13

def interpolate_string(string, scope)

  interp = string.clone

  while (matchdata = interp.match /%\{.+?\}/)
    var_name = matchdata[1].intern
    var_data = scope[var_name]
    interp.gsub!(/%\{#{var_name}\}/, var_data)
  end

  interp
end