Sha256: 23f1d7114da4565c23766882b36998b4efb6e588bc453603c1c82971807488e5

Contents?: true

Size: 704 Bytes

Versions: 8

Compression:

Stored size: 704 Bytes

Contents

require 'debugging'

module Debugging
  private

  def re(string, regex, groups = nil)
    if regex =~ string
      if !groups
        puts $` + Paint[$&, :green] + $'
      else
        Array( groups ).each{ |group_nr|
          begin
            raise IndexError unless $~[group_nr]
            gr_string = string.dup
            gr_string[ $~.end( group_nr ),   0 ] = Paint::NOTHING
            gr_string[ $~.begin( group_nr ), 0 ] = Paint.color(:green)
            puts group_nr.to_s + ': ' + gr_string
          rescue IndexError
            puts group_nr.to_s + ': ' + Paint['no match', :red]
          end
        }
      end
    else
      puts Paint['no match', :red]
    end

    nil
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
debugging-2.1.0 lib/debugging/re.rb
debugging-2.0.0 lib/debugging/re.rb
debugging-1.1.2 lib/debugging/re.rb
debugging-1.1.1 lib/debugging/re.rb
debugging-1.1.0 lib/debugging/re.rb
debugging-1.0.2 lib/debugging/re.rb
debugging-1.0.1 lib/debugging/re.rb
debugging-1.0.0 lib/debugging/re.rb