diff options
Diffstat (limited to 'lib/expand_variables.rb')
-rw-r--r-- | lib/expand_variables.rb | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/expand_variables.rb b/lib/expand_variables.rb index 40bf9483eb5..669735cc56c 100644 --- a/lib/expand_variables.rb +++ b/lib/expand_variables.rb @@ -1,15 +1,17 @@ -String.instance_eval - def expand_variables(variables) - # Convert hash array to variables - if variables.is_a?(Array) - variables = variables.reduce({}) do |hash, variable| - hash[variable[:key]] = variable[:value] - hash +module ExpandVariables + class << self + def expand_variables(value, variables) + # Convert hash array to variables + if variables.is_a?(Array) + variables = variables.reduce({}) do |hash, variable| + hash[variable[:key]] = variable[:value] + hash + end end - end - self.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do - variables[$1 || $2] + value.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do + variables[$1 || $2] + end end end end |