From c63e19c8a0ccca1ad30b90bc262f11919f5397c1 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 26 Sep 2009 03:48:49 +0200 Subject: [PATCH] AS guide: documents Regexp#multiline? --- .../source/active_support_overview.textile | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile index 89c959c49f31f..9c3610dc2cef8 100644 --- a/railties/guides/source/active_support_overview.textile +++ b/railties/guides/source/active_support_overview.textile @@ -1573,6 +1573,31 @@ def recognition_extraction end +h4. +multiline?+ + +The method +multiline?+ says whether a regexp has the +/m+ flag set, that is, whether the dot matches newlines. + + +%r{.}.multiline? # => false +%r{.}m.multiline? # => true + +Regexp.new('.').multiline? # => false +Regexp.new('.', Regexp::MULTILINE).multiline? # => true + + +Rails uses this method in a single place, also in the routing code. Multiline regexps are disallowed for route requirements and this flag eases enforcing that constraint. + + +def assign_route_options(segments, defaults, requirements) + ... + if requirement.multiline? + raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}" + end + ... +end + + + h3. Extensions to +Range+ ...