Class: Regexp

Inherits:
Object show all
Defined in:
lib/action_controller/routing.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.optionalize(pattern) ⇒ Object



33
34
35
36
37
38
# File 'lib/action_controller/routing.rb', line 33

def optionalize(pattern)
  case unoptionalize(pattern)
    when /\A(.|\(.*\))\Z/ then "#{pattern}?"
    else "(?:#{pattern})?"
  end
end

.unoptionalize(pattern) ⇒ Object



40
41
42
43
44
45
# File 'lib/action_controller/routing.rb', line 40

def unoptionalize(pattern)
  [/\A\(\?:(.*)\)\?\Z/, /\A(.|\(.*\))\?\Z/].each do |regexp|
    return $1 if regexp =~ pattern
  end
  return pattern
end

Instance Method Details

#number_of_capturesObject



28
29
30
# File 'lib/action_controller/routing.rb', line 28

def number_of_captures
  Regexp.new("|#{source}").match('').captures.length
end