Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

AS guide: documents Regexp#multiline?

  • Loading branch information...
commit c63e19c8a0ccca1ad30b90bc262f11919f5397c1 1 parent 23566b0
@fxn fxn authored
Showing with 25 additions and 0 deletions.
  1. +25 −0 railties/guides/source/active_support_overview.textile
View
25 railties/guides/source/active_support_overview.textile
@@ -1573,6 +1573,31 @@ def recognition_extraction
end
</ruby>
+h4. +multiline?+
+
+The method +multiline?+ says whether a regexp has the +/m+ flag set, that is, whether the dot matches newlines.
+
+<ruby>
+%r{.}.multiline? # => false
+%r{.}m.multiline? # => true
+
+Regexp.new('.').multiline? # => false
+Regexp.new('.', Regexp::MULTILINE).multiline? # => true
+</ruby>
+
+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.
+
+<ruby>
+def assign_route_options(segments, defaults, requirements)
+ ...
+ if requirement.multiline?
+ raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}"
+ end
+ ...
+end
+</ruby>
+
+
h3. Extensions to +Range+
...
Please sign in to comment.
Something went wrong with that request. Please try again.