ruby-changes:14629
From: yugui <ko1@a...>
Date: Sat, 30 Jan 2010 21:45:04 +0900 (JST)
Subject: [ruby-changes:14629] Ruby:r26474 (ruby_1_9_1): merges r25245 from trunk into ruby_1_9_1.
yugui 2010-01-30 21:44:47 +0900 (Sat, 30 Jan 2010) New Revision: 26474 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26474 Log: merges r25245 from trunk into ruby_1_9_1. and fixes a mistake in the test case. -- * 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. Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/lib/delegate.rb branches/ruby_1_9_1/test/test_delegate.rb branches/ruby_1_9_1/version.h Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 26473) +++ ruby_1_9_1/ChangeLog (revision 26474) @@ -1,3 +1,14 @@ +Mon Oct 5 17:19:33 2009 Yukihiro Matsumoto <matz@r...> + + * 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. + Tue Oct 6 18:56:09 2009 Yukihiro Matsumoto <matz@r...> * struct.c (rb_struct_select): Struct#select should return Index: ruby_1_9_1/lib/delegate.rb =================================================================== --- ruby_1_9_1/lib/delegate.rb (revision 26473) +++ ruby_1_9_1/lib/delegate.rb (revision 26474) @@ -196,6 +196,11 @@ 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 @@ 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 @@ 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: Index: ruby_1_9_1/version.h =================================================================== --- ruby_1_9_1/version.h (revision 26473) +++ ruby_1_9_1/version.h (revision 26474) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.1" -#define RUBY_PATCHLEVEL 379 +#define RUBY_PATCHLEVEL 380 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 Index: ruby_1_9_1/test/test_delegate.rb =================================================================== --- ruby_1_9_1/test/test_delegate.rb (revision 26473) +++ ruby_1_9_1/test/test_delegate.rb (revision 26474) @@ -30,4 +30,23 @@ simple=SimpleDelegator.new([]) assert_equal(SimpleDelegator,simple.class) end + + class Foo + def m + :m + end + end + + class Bar < DelegateClass(Foo) + end + + def test_override + ::Object.class_eval{ def m; :o end } + assert_equal(:o, Object.new.m) + assert_equal(:m, Foo.new.m) + assert_equal(:m, SimpleDelegator.new(Foo.new).m) + assert_equal(:m, Bar.new(Foo.new).m) + ensure + ::Object.class_eval{ remove_method :m } + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/