diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/delegation.rb | 7 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/blank.rb | 10 |
2 files changed, 9 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 0d46248582..24450cd221 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -149,14 +149,11 @@ class Module # # The target method must be public, otherwise it will raise +NoMethodError+. # - def delegate(*methods) - options = methods.pop - unless options.is_a?(Hash) && to = options[:to] + def delegate(*methods, to: nil, prefix: nil, allow_nil: nil) + unless to 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 - prefix, allow_nil = options.values_at(:prefix, :allow_nil) - if prefix == true && to =~ /^[^a-z_]/ raise ArgumentError, 'Can only automatically set the delegation prefix when delegating to a method.' end diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 039c50a4a2..d6bad98376 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -97,8 +97,6 @@ class Hash end class String - BLANK_RE = /\A[[:space:]]*\z/ - # A string is blank if it's empty or contains whitespaces only: # # ''.blank? # => true @@ -112,7 +110,13 @@ class String # # @return [true, false] def blank? - BLANK_RE === self + # In practice, the majority of blank strings are empty. The predicate is + # about 3.5x faster than the regexp check so we first test empty?, and then + # fallback. Penalty for the rest of strings is marginal. + # + # Double negation in the second operand is also a performance tweak, it is + # faster than the positive \A[[:space:]]*\z due to lack of backtracking. + empty? || !(/[[:^space:]]/ === self) end end |