class String
Constants
- INTERPOLATE_DELIMETER_LIST
- JSON_ESCAPE_MAP
Public Instance Methods
escape_json()
click to toggle source
# File lib/jekyll-patreon/utils/string-utils.rb, line 32 def escape_json self.gsub(/(\\|<\/|\r\n|[\n\r"])/) { JSON_ESCAPE_MAP[$1] } end
interpolate(data = {})
click to toggle source
# File lib/jekyll-patreon/utils/string-utils.rb, line 5 def interpolate(data = {}) binding = Kernel.binding data.each do |k, v| binding.local_variable_set(k, v) end delemeter = nil INTERPOLATE_DELIMETER_LIST.each do |k| next if self.include? k delemeter = k break end raise ArgumentError, "String contains all the reserved characters" unless delemeter e = s = delemeter string = "%Q#{s}" + self + "#{e}" binding.eval string end