From cfc91c31aa989826e992be29b6d5b181f654f853 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 22 Jul 2016 23:13:42 +0200 Subject: systematic revision of =~ usage in AS Where appropriate prefer the more concise Regexp#match?, String#include?, String#start_with?, and String#end_with? --- activesupport/lib/active_support/core_ext/module/delegation.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/module/delegation.rb') 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. -- cgit v1.2.3