提交 7c0b9624 编写于 作者: R Rafael França

Merge pull request #24666 from tlynam/patch-1

Update delegate to use newer Ruby syntax
......@@ -149,14 +149,11 @@ class DelegationError < NoMethodError; end
#
# 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册