Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/trunk/actionpack/lib/action_controller/routing/routing_ext.rb

Revision 8652, 0.7 kB (checked in by nzkoz, 11 months ago)

Restructure routing into several smaller files. References #10835 [oleganza]

Line 
1
2 class Object
3   def to_param
4     to_s
5   end
6 end
7
8 class TrueClass
9   def to_param
10     self
11   end
12 end
13
14 class FalseClass
15   def to_param
16     self
17   end
18 end
19
20 class NilClass
21   def to_param
22     self
23   end
24 end
25
26 class Regexp #:nodoc:
27   def number_of_captures
28     Regexp.new("|#{source}").match('').captures.length
29   end
30
31   class << self
32     def optionalize(pattern)
33       case unoptionalize(pattern)
34         when /\A(.|\(.*\))\Z/ then "#{pattern}?"
35         else "(?:#{pattern})?"
36       end
37     end
38
39     def unoptionalize(pattern)
40       [/\A\(\?:(.*)\)\?\Z/, /\A(.|\(.*\))\?\Z/].each do |regexp|
41         return $1 if regexp =~ pattern
42       end
43       return pattern
44     end
45   end
46 end
Note: See TracBrowser for help on using the browser.