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@57255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
363c7839fa
commit
46c0e79bb5
1 changed files with 3 additions and 3 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue