aboutsummaryrefslogtreecommitdiffstats
path: root/lib/delegate.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-06 13:07:12 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-06 13:07:12 +0000
commite1797bc7dd2178550cf15d7a6af4f7f0eae003b4 (patch)
tree577490c191adc749c2b2b4ec9fc56e5b704bae7d /lib/delegate.rb
parent1c544fccd27d399a444353905c8d921b1d1c5186 (diff)
downloadruby-e1797bc7dd2178550cf15d7a6af4f7f0eae003b4.tar.gz
* lib/delegate.rb (Delegator::public_api): take snapshot of
public method at the beginning time. * lib/delegate.rb (SimpleDelegator#initialize): use Delegator.public_api since public_method might be added after initialization. [ruby-dev:39383] * lib/delegate.rb (DelegateClass): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/delegate.rb')
-rw-r--r--lib/delegate.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/delegate.rb b/lib/delegate.rb
index d0b732aa8d..57c479c61b 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -196,6 +196,11 @@ class Delegator
new.__setobj__(__getobj__.dup)
new
end
+
+ @delegator_api = self.public_instance_methods
+ def self.public_api # :nodoc:
+ @delegator_api
+ end
end
#
@@ -228,6 +233,17 @@ class SimpleDelegator<Delegator
raise ArgumentError, "cannot delegate to self" if self.equal?(obj)
@delegate_sd_obj = obj
end
+
+ def initialize(obj) # :nodoc:
+ (self.public_methods - Delegator.public_api).each do |m|
+ class << self
+ self
+ end.class_eval do
+ undef_method m
+ end
+ end
+ super
+ end
end
# :stopdoc:
@@ -257,7 +273,7 @@ end
def DelegateClass(superclass)
klass = Class.new(Delegator)
methods = superclass.public_instance_methods(true)
- methods -= ::Delegator.public_instance_methods
+ methods -= ::Delegator.public_api
methods -= [:to_s,:inspect,:=~,:!~,:===]
klass.module_eval {
def __getobj__ # :nodoc: