Permalink
Browse files

AS guide: documents Regexp.optionalize

  • Loading branch information...
1 parent c63e19c commit ee289f42c618780ed7438867ca26961b29a942a7 @fxn fxn committed Sep 26, 2009
Showing with 11 additions and 0 deletions.
  1. +11 −0 railties/guides/source/active_support_overview.textile
@@ -1597,6 +1597,17 @@ def assign_route_options(segments, defaults, requirements)
end
</ruby>
+h4. +optionalize(pattern)+
+
+The class method +optionalize+ builds a regexp where the pattern argument is optional. That roughly means it gets a question mark appended with a non-capturing group if needed:
+
+<ruby>
+Regexp.optionalize('') # => ''
+Regexp.optionalize('.') # => '.?'
+Regexp.optionalize('...') # => '(?:...)?'
+</ruby>
+
+This method is also used by the routing system, it helps in building optional regexp segments.
h3. Extensions to +Range+

0 comments on commit ee289f4

Please sign in to comment.