diff options
author | Xavier Noria <fxn@hashref.com> | 2009-09-26 03:34:55 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2009-09-26 03:46:22 +0200 |
commit | 23566b071cf211e36d57b09898675fa73e2e7882 (patch) | |
tree | 63e9e48ebdc4e5d6a9906ceec8c36fdc54aeb96f /railties/guides/source/active_support_overview.textile | |
parent | 547865bc3d9fc0a4196f34a44d7968ea0cfdb4d9 (diff) | |
download | rails-23566b071cf211e36d57b09898675fa73e2e7882.tar.gz rails-23566b071cf211e36d57b09898675fa73e2e7882.tar.bz2 rails-23566b071cf211e36d57b09898675fa73e2e7882.zip |
AS guide: documents Regexp#number_of_captures
Diffstat (limited to 'railties/guides/source/active_support_overview.textile')
-rw-r--r-- | railties/guides/source/active_support_overview.textile | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile index 8e53672abd..89c959c49f 100644 --- a/railties/guides/source/active_support_overview.textile +++ b/railties/guides/source/active_support_overview.textile @@ -1547,6 +1547,32 @@ The method +with_indifferent_access+ returns an +ActiveSupport::HashWithIndiffer {:a => 1}.with_indifferent_access["a"] # => 1 </ruby> +h3. Extensions to +Regexp+ + +h4. +number_of_captures+ + +The method +number_of_captures+ returns the number of capturing groups in a given regexp: + +<ruby> +%r{}.number_of_captures # => 0 +%r{.(.).}.number_of_captures # => 1 +%r{\A((#)(\w+|\s+))\z}.number_of_captures # => 3 +</ruby> + +Routing code for example uses that method to generate path recognizers: + +<ruby> +def recognition_extraction + next_capture = 1 + extraction = segments.collect do |segment| + x = segment.match_extraction(next_capture) + next_capture += segment.number_of_captures + x + end + extraction.compact +end +</ruby> + h3. Extensions to +Range+ ... |