diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-10-06 13:07:12 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-10-06 13:07:12 +0000 |
| commit | 03ea3b060cc5d55d391a6af3d54b6daa0fb62a17 (patch) | |
| tree | 577490c191adc749c2b2b4ec9fc56e5b704bae7d /lib | |
| parent | 1f539dba0667949e42ec9603af3d7e7fb784781f (diff) | |
| download | ruby-03ea3b060cc5d55d391a6af3d54b6daa0fb62a17.tar.gz ruby-03ea3b060cc5d55d391a6af3d54b6daa0fb62a17.tar.xz ruby-03ea3b060cc5d55d391a6af3d54b6daa0fb62a17.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@25245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/delegate.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/delegate.rb b/lib/delegate.rb index d0b732aa8..57c479c61 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: |
