diff options
author | Todd Lynam <TLynam@gmail.com> | 2016-04-20 18:35:43 -0700 |
---|---|---|
committer | Todd Lynam <TLynam@gmail.com> | 2016-04-20 18:35:43 -0700 |
commit | 406047d3acf94e3ce15705f870881632f631c52d (patch) | |
tree | 5344eca15a7f308aec9cf6e9dfded4a751203c2f /activesupport/lib | |
parent | 778ab950084ea00f6ce0c731157e8e5cc22d1bf7 (diff) | |
download | rails-406047d3acf94e3ce15705f870881632f631c52d.tar.gz rails-406047d3acf94e3ce15705f870881632f631c52d.tar.bz2 rails-406047d3acf94e3ce15705f870881632f631c52d.zip |
Update delegate to use newer Ruby syntax
This commit updates `delegate` to use the keyword argument syntax added in Ruby 2. I left the `ArgumentError` when `to` is missing, because it better explains how to correctly use `delegate`. We could instead rely on the default `ArgumentError` that would be raised if `to` were a required keyword argument.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/delegation.rb | 7 |
1 files changed, 2 insertions, 5 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 |