From 8bba95f293714283f6fc30cb213af54811cccff3 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Mon, 18 Jul 2011 16:06:21 +0100 Subject: Just do the method call directly in Module#delegate, if we can (we cannot for method names ending in '='). Two reasons: 1) it's faster, see https://gist.github.com/1089783 and 2) more importantly, delegate should not allow you to accidentally call private or protected methods. --- activesupport/lib/active_support/core_ext/module/delegation.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index bf7e009290..8655288bc3 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -123,6 +123,9 @@ class Module line = line.to_i methods.each do |method| + method = method.to_s + call = (method[-1..-1] == '=') ? "public_send(:#{method}, " : "#{method}(" + on_nil = if allow_nil 'return' @@ -132,7 +135,7 @@ class Module module_eval(<<-EOS, file, line - 5) def #{method_prefix}#{method}(*args, &block) # def customer_name(*args, &block) - #{to}.__send__(#{method.inspect}, *args, &block) # client.__send__(:name, *args, &block) + #{to}.#{call}*args, &block) # client.name(*args, &block) rescue NoMethodError # rescue NoMethodError if #{to}.nil? # if client.nil? #{on_nil} # return # depends on :allow_nil -- cgit v1.2.3