diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-01-03 09:35:26 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-01-03 09:35:26 +0000 |
commit | a50cc9ce082a9e356d0bc188785973ebbd0529ff (patch) | |
tree | 2bbc13cadac2e74d20b22f5228da6c20b8710690 | |
parent | 46c0e79bb5b96c45c166ef62f8e585f528862abb (diff) | |
download | ruby-a50cc9ce082a9e356d0bc188785973ebbd0529ff.tar.gz |
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
-rw-r--r-- | lib/forwardable.rb | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/lib/forwardable.rb b/lib/forwardable.rb index cc5ac15001..ef2cf74370 100644 --- a/lib/forwardable.rb +++ b/lib/forwardable.rb @@ -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 # |