Module: ExpandVariables

Defined in:
lib/expand_variables.rb

Class Method Summary collapse

Class Method Details

.expand(value, variables) ⇒ Object


5
6
7
8
9
10
11
12
# File 'lib/expand_variables.rb', line 5

def expand(value, variables)
  variables_hash = nil

  value.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do
    variables_hash ||= transform_variables(variables)
    variables_hash[Regexp.last_match(1) || Regexp.last_match(2)]
  end
end