Sha256: 544001d6434c77328fb02c9ee69db696fd32c770575bdcc1e0156f79744df981

Contents?: true

Size: 502 Bytes

Versions: 1

Compression:

Stored size: 502 Bytes

Contents

class String
  INTERPOLATION_PATTERN = Regexp.union(
    /%%/,
    /%\{(\w+)\}/
  )
  def interpolate(values)
    self.gsub(INTERPOLATION_PATTERN) do |match|
      if match == '%%'
        '%'
      else
        key = ($1 || $2).to_sym
        unless values.key?(key)
          raise "Mission interpolation argument: #{key}"
        end
        value = values[key]
        value = value.call(values) if value.respond_to?(:call)
        $3 ? sprintf("%#{$3}", value) : value
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yolo_backup-0.0.0 lib/yolo_backup/core_ext/string.rb