[前][次][番号順一覧][スレッド一覧]

ruby-changes:16140

From: marcandre <ko1@a...>
Date: Mon, 31 May 2010 01:44:04 +0900 (JST)
Subject: [ruby-changes:16140] Ruby:r28099 (trunk): * lib/delegate: Delegator: combine (public|protected) methods with

marcandre	2010-05-31 01:43:52 +0900 (Mon, 31 May 2010)

  New Revision: 28099

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28099

  Log:
    * lib/delegate: Delegator: combine (public|protected) methods with
      those of the delegated object. [ruby-core:27224]
      DelegateClass: combine (public|protected) instance methods
      with those of the delegated superclass.

  Modified files:
    trunk/ChangeLog
    trunk/lib/delegate.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 28098)
+++ ChangeLog	(revision 28099)
@@ -1,3 +1,10 @@
+Mon May 31 01:43:42 2010  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* lib/delegate: Delegator: combine (public|protected) methods with
+	  those of the delegated object. [ruby-core:27224]
+	  DelegateClass: combine (public|protected) instance methods
+	  with those of the delegated superclass.
+
 Sun May 30 22:18:49 2010  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* lib/set.rb (keep_if, select!): New methods [ruby-core:29749]
Index: lib/delegate.rb
===================================================================
--- lib/delegate.rb	(revision 28098)
+++ lib/delegate.rb	(revision 28099)
@@ -161,6 +161,32 @@
   end
 
   #
+  # Returns the methods available to this delegate object as the union
+  # of this object's and \_\_getobj\_\_ methods.
+  #
+  def methods
+    __getobj__.methods | super
+  end
+
+  #
+  # Returns the methods available to this delegate object as the union
+  # of this object's and \_\_getobj\_\_ public methods.
+  #
+  def public_methods(all=true)
+    __getobj__.public_methods(all) | super
+  end
+
+  #
+  # Returns the methods available to this delegate object as the union
+  # of this object's and \_\_getobj\_\_ protected methods.
+  #
+  def protected_methods(all=true)
+    __getobj__.protected_methods(all) | super
+  end
+
+  # Note: no need to specialize private_methods, since they are not forwarded
+
+  #
   # Returns true if two objects are considered same.
   #
   def ==(obj)
@@ -281,10 +307,10 @@
 #
 def DelegateClass(superclass)
   klass = Class.new(Delegator)
-  methods = superclass.public_instance_methods(true)
+  methods = superclass.instance_methods
   methods -= ::Delegator.public_api
   methods -= [:to_s,:inspect,:=~,:!~,:===]
-  klass.module_eval {
+  klass.module_eval do
     def __getobj__  # :nodoc:
       @delegate_dc_obj
     end
@@ -292,12 +318,16 @@
       raise ArgumentError, "cannot delegate to self" if self.equal?(obj)
       @delegate_dc_obj = obj
     end
-  }
-  klass.module_eval do
     methods.each do |method|
       define_method(method, Delegator.delegating_block(method))
     end
   end
+  klass.define_singleton_method :public_instance_methods do |all=true|
+    super(all) - superclass.protected_instance_methods
+  end
+  klass.define_singleton_method :protected_instance_methods do |all=true|
+    super(all) | superclass.protected_instance_methods
+  end
   return klass
 end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]