aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/delegation.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-07-22 23:13:42 +0200
committerXavier Noria <fxn@hashref.com>2016-07-22 23:13:49 +0200
commitcfc91c31aa989826e992be29b6d5b181f654f853 (patch)
treeb5ec5569b22f8c796de89335c5ecc7de047130bc /activesupport/lib/active_support/core_ext/module/delegation.rb
parentaea0e5cd709e0fc53e1ba4e87235b8ee3f4bc155 (diff)
downloadrails-cfc91c31aa989826e992be29b6d5b181f654f853.tar.gz
rails-cfc91c31aa989826e992be29b6d5b181f654f853.tar.bz2
rails-cfc91c31aa989826e992be29b6d5b181f654f853.zip
systematic revision of =~ usage in AS
Where appropriate prefer the more concise Regexp#match?, String#include?, String#start_with?, and String#end_with?
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module/delegation.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/module/delegation.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb
index 3f6e8bd26c..946a0f4177 100644
--- a/activesupport/lib/active_support/core_ext/module/delegation.rb
+++ b/activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -1,4 +1,5 @@
require 'set'
+require 'active_support/core_ext/regexp'
class Module
# Error generated by +delegate+ when a method is called on +nil+ and +allow_nil+
@@ -153,7 +154,7 @@ class Module
raise ArgumentError, 'Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, to: :greeter).'
end
- if prefix == true && to =~ /^[^a-z_]/
+ if prefix == true && /^[^a-z_]/.match?(to)
raise ArgumentError, 'Can only automatically set the delegation prefix when delegating to a method.'
end
@@ -173,7 +174,7 @@ class Module
methods.each do |method|
# Attribute writer methods only accept one argument. Makes sure []=
# methods still accept two arguments.
- definition = (method =~ /[^\]]=$/) ? 'arg' : '*args, &block'
+ definition = /[^\]]=$/.match?(method) ? 'arg' : '*args, &block'
# The following generated method calls the target exactly once, storing
# the returned value in a dummy variable.