Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/Getopt/DelimScanner.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#interpolate(scope) ⇒ Object

Ideas for String-interpolation stuff courtesy of Hal E. Fulton <[email protected]> via ruby-talk



47
48
49
50
51
52
53
54
55
56
57
# 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) ⇒ Object



40
41
42
# File 'lib/Getopt/DelimScanner.rb', line 40

def to_re( casefold=false, extended=false )
    return Regexp::new( self.dup )
end