1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

forwardable.rb: use defined?

* lib/forwardable.rb (_delegator_method): use defined? operator
  instead of binding and calling unbound Kernel#respond_to?.  a
  remedy for an performance bottleneck.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-01-03 09:35:26 +00:00
parent 46c0e79bb5
commit a50cc9ce08

View file

@ -130,12 +130,13 @@ module Forwardable
# delegate [method, method, ...] => accessor
#
def instance_delegate(hash)
hash.each{ |methods, accessor|
methods = [methods] unless defined?(methods.each)
methods.each{ |method|
def_instance_delegator(accessor, method)
}
}
hash.each do |methods, accessor|
if defined?(methods.each)
def_instance_delegator(accessor, methods)
else
methods.each {|method| def_instance_delegator(accessor, method)}
end
end
end
#
@ -261,12 +262,13 @@ module SingleForwardable
# delegate [method, method, ...] => accessor
#
def single_delegate(hash)
hash.each{ |methods, accessor|
methods = [methods] unless defined?(methods.each)
methods.each{ |method|
def_single_delegator(accessor, method)
}
}
hash.each do |methods, accessor|
if defined?(methods.each)
def_single_delegator(accessor, methods)
else
methods.each {|method| def_single_delegator(accessor, method)}
end
end
end
#