diff options
author | Xavier Noria <fxn@hashref.com> | 2009-09-26 03:56:48 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2009-09-26 04:06:40 +0200 |
commit | ee289f42c618780ed7438867ca26961b29a942a7 (patch) | |
tree | b563ccdc698a3ab0cd023664e88e1af56ba20286 /railties/guides/source | |
parent | c63e19c8a0ccca1ad30b90bc262f11919f5397c1 (diff) | |
download | rails-ee289f42c618780ed7438867ca26961b29a942a7.tar.gz rails-ee289f42c618780ed7438867ca26961b29a942a7.tar.bz2 rails-ee289f42c618780ed7438867ca26961b29a942a7.zip |
AS guide: documents Regexp.optionalize
Diffstat (limited to 'railties/guides/source')
-rw-r--r-- | railties/guides/source/active_support_overview.textile | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile index 9c3610dc2c..290b1e441e 100644 --- a/railties/guides/source/active_support_overview.textile +++ b/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+ |