A factory method that returns a new
segment instance appropriate for the format of the given string.
# File actionpack/lib/action_controller/routing/builder.rb, line 41
def segment_for(string)
segment = case string
when /\A:(\w+)/
key = $1.to_sym
case key
when :controller then ControllerSegment.new(key)
else DynamicSegment.new key
end
when /\A\*(\w+)/ then PathSegment.new($1.to_sym, :optional => true)
when /\A\?(.*?)\?/
returning segment = StaticSegment.new($1) do
segment.is_optional = true
end
when /\A(#{separator_pattern(:inverted)}+)/ then StaticSegment.new($1)
when Regexp.new(separator_pattern) then
returning segment = DividerSegment.new($&) do
segment.is_optional = (optional_separators.include? $&)
end
end
[segment, $~.post_match]
end