| Class | String |
| In: |
lib/mues/utils.rb
(CVS)
|
| Parent: | Object |
Add some stuff to the String class to allow easy transformation to Regexp and in-place interpolation.
Interpolate any ’#{…}’ placeholders in the string within the given scope (a Binding object).
# File lib/mues/utils.rb, line 83 def interpolate( scope ) unless scope.is_a?( Binding ) raise TypeError, "Argument to interpolate must be a Binding, not "\ "a #{scope.class.name}" end # $stderr.puts ">>> Interpolating '#{self}'..." copy = self.gsub( /"/, %q:\": ) eval( '"' + copy + '"', scope ) rescue Exception => err nicetrace = err.backtrace.find_all {|frame| /in `(interpolate|eval)'/i !~ frame } Kernel::raise( err, err.message, nicetrace ) end