Sha256: 47f0ca6771a4bff3e3ffdfefbac4195da9558ed4dd805689c4c8e171c1e68297

Contents?: true

Size: 309 Bytes

Versions: 2

Compression:

Stored size: 309 Bytes

Contents

module CoreExt
  module String
    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)
        h[key]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stir-2.2.1 lib/stir/core_ext/string.rb
stir-2.1.1 lib/stir/core_ext/string.rb