class Object
Public Instance Methods
the_interpolate(str, params = {})
click to toggle source
# File lib/the_interpolate.rb, line 5 def the_interpolate str, params = {} params.each_pair do |key, val| ary = str.split("[:#{ key }:]") str = ary.join val.to_s if ary.size > 1 end # Lazy (Ungreedy) regexp # word_char => \w # non_word_char => \W # digit => \d # non_digit => \D # lazy => *? str .gsub(/\.+/, '.') # try to protect of escape from Dir .gsub(/~/, '') # try to protect of escape from Dir .gsub(/\[:[\w\W\d\D]*?:\]/, '') # cleanup unused interpolation keys end