aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-07-21 23:41:03 +0200
committerXavier Noria <fxn@hashref.com>2016-07-22 00:15:52 +0200
commit575dbeeefcaafeb566afc07cdd8b55603b698d9f (patch)
tree8371e5e85e11f242c0fbb6fb42fb63b5edac6fa4 /guides
parentd4ea18a8cb84601509ee4c6dc691b212af8c2c36 (diff)
downloadrails-575dbeeefcaafeb566afc07cdd8b55603b698d9f.tar.gz
rails-575dbeeefcaafeb566afc07cdd8b55603b698d9f.tar.bz2
rails-575dbeeefcaafeb566afc07cdd8b55603b698d9f.zip
define Range#match? if Ruby < 2.4
See the rationale in the documentation included in this patch. We are going to gradually introduce this predicate in the code base.
Diffstat (limited to 'guides')
-rw-r--r--guides/source/active_support_core_extensions.md18
1 files changed, 18 insertions, 0 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md
index e0b6f2f820..27478b21a0 100644
--- a/guides/source/active_support_core_extensions.md
+++ b/guides/source/active_support_core_extensions.md
@@ -2916,6 +2916,24 @@ end
NOTE: Defined in `active_support/core_ext/regexp.rb`.
+### `match?`
+
+Rails implements `Regexp#match?` for Ruby versions prior to 2.4:
+
+```ruby
+/oo/.match?('foo') # => true
+/oo/.match?('bar') # => false
+/oo/.match?('foo', 1) # => true
+```
+
+The backport has the same interface and lack of side-effects in the caller like
+not setting `$1` and friends, but it does not have the speed benefits. Its
+purpose is to be able to write 2.4 compatible code. Rails itself uses this
+predicate internally for example.
+
+Active Support defines `Regexp#match?` only if not present, so code running
+under 2.4 or later does run the original one and gets the performance boost.
+
Extensions to `Range`
---------------------