From 8ba491acc31bf08cf63a83ea0a3c314c52cd020f Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 25 Aug 2011 18:51:17 +0100 Subject: Revert all the stuff to do with disallowing non-public methods for Module#delegate --- .../active_support/core_ext/module/delegation.rb | 8 ++----- .../lib/active_support/core_ext/object.rb | 1 - .../active_support/core_ext/object/public_send.rb | 25 ---------------------- 3 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/object/public_send.rb (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 8350753f78..7de824a77f 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -1,6 +1,3 @@ -require 'active_support/core_ext/object/public_send' -require 'active_support/core_ext/string/starts_ends_with' - class Module # Provides a delegate class method to easily expose contained objects' methods # as your own. Pass one or more methods (specified as symbols or strings) @@ -127,13 +124,12 @@ class Module methods.each do |method| method = method.to_s - call = method.ends_with?('=') ? "public_send(:#{method}, " : "#{method}(" if allow_nil module_eval(<<-EOS, file, line - 2) def #{method_prefix}#{method}(*args, &block) # def customer_name(*args, &block) if #{to} || #{to}.respond_to?(:#{method}) # if client || client.respond_to?(:name) - #{to}.#{call}*args, &block) # client.name(*args, &block) + #{to}.__send__(:#{method}, *args, &block) # client.__send__(:name, *args, &block) end # end end # end EOS @@ -142,7 +138,7 @@ class Module module_eval(<<-EOS, file, line - 1) def #{method_prefix}#{method}(*args, &block) # def customer_name(*args, &block) - #{to}.#{call}*args, &block) # client.name(*args, &block) + #{to}.__send__(:#{method}, *args, &block) # client.__send__(:name, *args, &block) rescue NoMethodError # rescue NoMethodError if #{to}.nil? # if client.nil? #{exception} # # add helpful message to the exception diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 249c2e93c5..9ad1e12699 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -3,7 +3,6 @@ require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/duplicable' require 'active_support/core_ext/object/try' require 'active_support/core_ext/object/inclusion' -require 'active_support/core_ext/object/public_send' require 'active_support/core_ext/object/conversions' require 'active_support/core_ext/object/instance_variables' diff --git a/activesupport/lib/active_support/core_ext/object/public_send.rb b/activesupport/lib/active_support/core_ext/object/public_send.rb deleted file mode 100644 index 2e77a22c4b..0000000000 --- a/activesupport/lib/active_support/core_ext/object/public_send.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'active_support/core_ext/kernel/singleton_class' - -class Object - unless Object.public_method_defined?(:public_send) - # Backports Object#public_send from 1.9 - def public_send(method, *args, &block) - # Don't create a singleton class for the object if it doesn't already have one - # (This also protects us from classes like Fixnum and Symbol, which cannot have a - # singleton class.) - klass = singleton_methods.any? ? self.singleton_class : self.class - - if klass.public_method_defined?(method) - send(method, *args, &block) - else - if klass.private_method_defined?(method) - raise NoMethodError, "private method `#{method}' called for #{inspect}" - elsif klass.protected_method_defined?(method) - raise NoMethodError, "protected method `#{method}' called for #{inspect}" - else - raise NoMethodError, "undefined method `#{method}' for #{inspect}" - end - end - end - end -end -- cgit v1.2.3