Bugs item #1905, was opened at 2005-05-13 11:39
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=1905&group_id=426

Category: Standard Library
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Dave Burt (dburt)
Assigned to: Nobody (None)
Summary: Delegate objects recurse infinitely on delegation to self

Initial Comment:
A delegating object created by the delegate module in the standard library has this (obvious?) issue.

I propose to have delegate deal with this problem more gracefully by:

1) Simply ignoring any request to delegate to self;
OR
2) Raising an exception in this case (fail early)

Patches for each of these are below:

1)
--- delegate.rb.bak     Thu May 12 00:16:14 2005
+++ delegate.rb Thu May 12 00:16:17 2005
@@ -73,7 +73,7 @@
   end

   def __setobj__(obj)
-    @_sd_obj = obj
+    @_sd_obj = obj unless eql?(obj)
   end

   def clone
@@ -110,7 +110,7 @@
       @_dc_obj
     end
     def __setobj__(obj)
-      @_dc_obj = obj
+      @_dc_obj = obj unless eql?(obj)
     end
     def clone
       super 

2)
--- delegate.rb.bak     Thu May 12 00:16:14 2005
+++ delegate.rb Thu May 12 00:16:17 2005
@@ -73,7 +73,7 @@
   end

   def __setobj__(obj)
+    raise ArgumentException("cannot delegate to self") if eql?(obj)
     @_sd_obj = obj
   end

   def clone
@@ -110,7 +110,7 @@
       @_dc_obj
     end
     def __setobj__(obj)
+      raise ArgumentException("cannot delegate to self") if eql?(obj)
       @_dc_obj = obj
     end
     def clone
       super 

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=1905&group_id=426