Module: CoreExt::String
- Defined in:
- lib/stir/core_ext/string.rb
Instance Method Summary collapse
Instance Method Details
#interpolate(h) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# 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 |