* 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
Родитель 46c0e79bb5
Коммит a50cc9ce08
1 изменённых файлов: 14 добавлений и 12 удалений

Просмотреть файл

@ -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
#