module EleetScript::Interpolatable

Constants

INTERPOLATE_RX

Public Instance Methods

interpolate(str, context) click to toggle source
# File lib/lang/interpreter.rb, line 68
def interpolate(str, context)
  new_val = str.dup
  matches = str.scan(INTERPOLATE_RX)
  matches.each do |match|
    next if match.nil? || match == "%" || match == ""
    if match.start_with?("\\")
      next new_val.sub!(match, match[1..-1])
    end
    var = match[1..-1]
    new_val.sub!(match, context[var].call(:to_string).ruby_value)
  end
  new_val
end