aboutsummaryrefslogtreecommitdiffstats
path: root/lib/forwardable.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-03 08:40:51 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-03 08:40:51 +0000
commiteaa8974ec115321c456281d27b1dc09aaf399897 (patch)
tree0757e70188c4d39c2194406cfb3f332eebe22ef1 /lib/forwardable.rb
parentec9f197d9b087f1fa7e54f6cb5d7742b609cff0b (diff)
downloadruby-eaa8974ec115321c456281d27b1dc09aaf399897.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@57255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/forwardable.rb')
-rw-r--r--lib/forwardable.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/forwardable.rb b/lib/forwardable.rb
index 0c04fb3a27..cc5ac15001 100644
--- a/lib/forwardable.rb
+++ b/lib/forwardable.rb
@@ -131,7 +131,7 @@ module Forwardable
#
def instance_delegate(hash)
hash.each{ |methods, accessor|
- methods = [methods] unless methods.respond_to?(:each)
+ methods = [methods] unless defined?(methods.each)
methods.each{ |method|
def_instance_delegator(accessor, method)
}
@@ -204,7 +204,7 @@ module Forwardable
mesg = "#{Module === obj ? obj : obj.class}\##{ali} at #{loc.path}:#{loc.lineno} forwarding to private method "
method_call = "#{<<-"begin;"}\n#{<<-"end;".chomp}"
begin;
- unless ::Kernel.instance_method(:respond_to?).bind(_).call(:"#{method}")
+ unless defined? _.#{method}
::Kernel.warn "\#{caller_locations(1)[0]}: "#{mesg.dump}"\#{_.class}"'##{method}'
_#{method_call}
else
@@ -262,7 +262,7 @@ module SingleForwardable
#
def single_delegate(hash)
hash.each{ |methods, accessor|
- methods = [methods] unless methods.respond_to?(:each)
+ methods = [methods] unless defined?(methods.each)
methods.each{ |method|
def_single_delegator(accessor, method)
}