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.

Methods

interpolate   to_re  

Public Instance methods

Interpolate any ’#{…}’ placeholders in the string within the given scope (a Binding object).

[Source]

# 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

[Source]

# File lib/mues/utils.rb, line 74
    def to_re( casefold=false, extended=false )
        return Regexp::new( self.dup )
    end

[Validate]