Class: Regexp

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

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.optionalize(pattern) ⇒ Object


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

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

.unoptionalize(pattern) ⇒ Object


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

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

Instance Method Details

#multiline?Boolean

Returns:

  • (Boolean)

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

def multiline?
  options & MULTILINE == MULTILINE
end

#number_of_capturesObject


26
27
28
# File 'lib/action_controller/routing/routing_ext.rb', line 26

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