Class: Regexp
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.optionalize(pattern) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/action_controller/routing/routing_ext.rb', line 32 def optionalize(pattern) case unoptionalize(pattern) when /\A(.|\(.*\))\Z/ then "#{pattern}?" else "(?:#{pattern})?" end end |
.unoptionalize(pattern) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/action_controller/routing/routing_ext.rb', line 39 def unoptionalize(pattern) [/\A\(\?:(.*)\)\?\Z/, /\A(.|\(.*\))\?\Z/].each do |regexp| return $1 if regexp =~ pattern end return pattern end |