class String

Add some stuff to the String class to allow easy transformation to Regexp and in-place interpolation.

Public Instance Methods

interpolate( scope ) click to toggle source

Ideas for String-interpolation stuff courtesy of Hal E. Fulton <hal9000@hypermetrics.com> via ruby-talk

# File lib/Getopt/DelimScanner.rb, line 47
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 )
end
to_re( casefold=false, extended=false ) click to toggle source
# File lib/Getopt/DelimScanner.rb, line 40
def to_re( casefold=false, extended=false )
    return Regexp::new( self.dup )
end