Parent

String

An add-on to the String class


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

Public Instance Methods

expand_tabs( tabstop = 8 ) click to toggle source

Return new string with all tabs set to spaces

# File lib/Getopt/Declare.rb, line 51
def expand_tabs( tabstop = 8 )
  h = self.dup
  while h.sub!(/(^|\n)([^\t\n]*)(\t+)/ex) { |f|
      val = ( tabstop * "#$3".length() - ("#$2".length() % tabstop) )
      "#$1#$2" + (" " * val)
    }
  end
  h
end
expand_tabs!( tabstop = 8 ) click to toggle source

Expand all tabs to spaces

# File lib/Getopt/Declare.rb, line 41
def expand_tabs!( tabstop = 8 )
  while self.sub!(/(^|\n)([^\t\n]*)(\t+)/ex) { |f|
      val = ( tabstop * "#$3".length() - ("#$2".length() % tabstop) )
      "#$1#$2" + (" " * val)
    }
  end
  self
end
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( /"/, %\": )
    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

[Validate]

Generated with the Darkfish Rdoc Generator 2.