ruby-changes:45183
From: nobu <ko1@a...>
Date: Tue, 3 Jan 2017 18:35:30 +0900 (JST)
Subject: [ruby-changes:45183] nobu:r57256 (trunk): forwardable.rb: use defined?
nobu 2017-01-03 18:35:26 +0900 (Tue, 03 Jan 2017) New Revision: 57256 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57256 Log: 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. Modified files: trunk/lib/forwardable.rb Index: lib/forwardable.rb =================================================================== --- lib/forwardable.rb (revision 57255) +++ lib/forwardable.rb (revision 57256) @@ -130,12 +130,13 @@ module Forwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L130 # 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 https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L262 # 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 # -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/