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



36
37
38
39
40
41
# File 'lib/action_controller/routing.rb', line 36

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

.unoptionalize(pattern) ⇒ Object



43
44
45
46
47
48
# File 'lib/action_controller/routing.rb', line 43

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



31
32
33
# File 'lib/action_controller/routing.rb', line 31

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