Regexp
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]+)/
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
# File lib/rack/mount/regexp_with_named_groups.rb, line 64 64: def eql?(other) 65: super && @names.eql?(other.names) 66: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.