aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorAkira Matsuda <ronnie@dio.jp>2019-07-27 12:56:39 +0900
committerAkira Matsuda <ronnie@dio.jp>2019-07-27 13:06:49 +0900
commitd1ffe59ab5fd6e811833c127d43b32e87b5d7131 (patch)
treec866689e6b51b1f7eac9e49212d2938d56f6ecb2 /activemodel
parente9651deea4145f62224af56af027bfbb3e45e4cd (diff)
downloadrails-d1ffe59ab5fd6e811833c127d43b32e87b5d7131.tar.gz
rails-d1ffe59ab5fd6e811833c127d43b32e87b5d7131.tar.bz2
rails-d1ffe59ab5fd6e811833c127d43b32e87b5d7131.zip
Use match? where we don't need MatchData
We're already running Performance/RegexpMatch cop, but it seems like the cop is not always =~ justice
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/validations/format.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb
index bea57415b0..a473440b4e 100644
--- a/activemodel/lib/active_model/validations/format.rb
+++ b/activemodel/lib/active_model/validations/format.rb
@@ -6,7 +6,7 @@ module ActiveModel
def validate_each(record, attribute, value)
if options[:with]
regexp = option_call(record, :with)
- record_error(record, attribute, :with, value) if value.to_s !~ regexp
+ record_error(record, attribute, :with, value) unless regexp.match?(value.to_s)
elsif options[:without]
regexp = option_call(record, :without)
record_error(record, attribute, :without, value) if regexp.match?(value.to_s)