Parent

Rack::Mount::RegexpWithNamedGroups

A wrapper that adds shim named capture support to older versions of Ruby.

Because the named capture syntax causes a parse error, an alternate syntax is used to indicate named captures.

Ruby 1.9+ named capture syntax:

  /(?<foo>[a-z]+)/

Ruby 1.8 shim syntax:

  /(?:<foo>[a-z]+)/

Public Class Methods

new(regexp) click to toggle source

Wraps Regexp with named capture support.

    # File lib/rack/mount/regexp_with_named_groups.rb, line 30
30:       def initialize(regexp)
31:         regexp = Regexp.compile(regexp) unless regexp.is_a?(Regexp)
32:         source, options = regexp.source, regexp.options
33:         @names, scanner = [], StringScanner.new(source)
34: 
35:         while scanner.skip_until(/\(/)
36:           if scanner.scan(/\?:<([^>]+)>/)
37:             @names << scanner[1]
38:           elsif scanner.scan(/\?(i?m?x?\-?i?m?x?)?:/)
39:             # ignore noncapture
40:           else
41:             @names << nil
42:           end
43:         end
44:         source.gsub!(/\?:<([^>]+)>/, '')
45: 
46:         @names = [] unless @names.any?
47:         @names.freeze
48: 
49:         super(source, options)
50:       end

Public Instance Methods

eql?(other) click to toggle source
    # File lib/rack/mount/regexp_with_named_groups.rb, line 64
64:       def eql?(other)
65:         super && @names.eql?(other.names)
66:       end
named_captures() click to toggle source
    # File lib/rack/mount/regexp_with_named_groups.rb, line 56
56:       def named_captures
57:         named_captures = {}
58:         names.each_with_index { |n, i|
59:           named_captures[n] = [i+1] if n
60:         }
61:         named_captures
62:       end
names() click to toggle source
    # File lib/rack/mount/regexp_with_named_groups.rb, line 52
52:       def names
53:         @names.dup
54:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.