module CoreExt::String

Public Instance Methods

interpolate(h) click to toggle source
# File lib/stir/core_ext/string.rb, line 3
def interpolate(h)
  return self if h.nil?
  self.gsub(/%({\w+})/) do |match|
    return self if match.nil?
    key = $1.tr('{}', '').to_sym
    raise KeyError.new("key{#{key}} not found") unless h.has_key?(key)
    CGI::escape(h[key].to_s)
  end
end