Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/support/string.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#interpolate(*args) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/support/string.rb', line 2 def interpolate(*args) if args.length > 1 replacements = Hash[*args] elsif args.first.kind_of?(Hash) replacements = args.first else raise ArgumentError, "Must pass hash to interpolate." end string = self.dup replacements.each do |key, value| if key.kind_of?(Regexp) string.gsub!(key, value.to_s) else string.gsub!(/#{key}/i, value.to_s) end end string end |