From 711b655f38b200cd127c2626679a8d41b0415411 Mon Sep 17 00:00:00 2001 From: seki Date: Sun, 31 Jul 2005 16:19:42 +0000 Subject: use private_methods and protected_methods instead of respond_to? to check method visibility. [ruby-dev:26616] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/drb/drb.rb | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb index a9b0c99bb3..2177af871b 100644 --- a/lib/drb/drb.rb +++ b/lib/drb/drb.rb @@ -1448,7 +1448,9 @@ module DRb # Coerce an object to a string, providing our own representation if # to_s is not defined for the object. def any_to_s(obj) - obj.to_s rescue sprintf("#<%s:0x%lx>", obj.class, obj.__id__) + obj.to_s + ":#{obj.class}" + rescue + sprintf("#<%s:0x%lx>", obj.class, obj.__id__) end # Check that a method is callable via dRuby. @@ -1463,22 +1465,19 @@ module DRb return true if Proc === obj && msg_id == :__drb_yield raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id) - unless obj.respond_to?(msg_id) + + if obj.private_methods.include?(msg_id.to_s) desc = any_to_s(obj) - if desc.nil? || desc[0] == '#' - desc << ":#{obj.class}" - end - - if obj.private_methods.include?(msg_id.to_s) - raise NameError, "private method `#{msg_id}' called for #{desc}" - else - raise NameError, "undefined method `#{msg_id}' called for #{desc}" - end + raise NoMethodError, "private method `#{msg_id}' called for #{desc}" + elsif obj.protected_methods.include?(msg_id.to_s) + desc = any_to_s(obj) + raise NoMethodError, "protected method `#{msg_id}' called for #{desc}" + else + true end - true end public :check_insecure_method - + class InvokeMethod # :nodoc: def initialize(drb_server, client) @drb_server = drb_server -- cgit v1.2.3