[#25936] [Bug:1.9] [rubygems] $LOAD_PATH includes bin directory — Nobuyoshi Nakada <nobu@...>

Hi,

10 messages 2009/10/05

[#25943] Disabling tainting — Tony Arcieri <tony@...>

Would it make sense to have a flag passed to the interpreter on startup that

16 messages 2009/10/05

[#26028] [Bug #2189] Math.atanh(1) & Math.atanh(-1) should not raise an error — Marc-Andre Lafortune <redmine@...>

Bug #2189: Math.atanh(1) & Math.atanh(-1) should not raise an error

14 messages 2009/10/10

[#26222] [Bug #2250] IO::for_fd() objects' finalization dangerously closes underlying fds — Mike Pomraning <redmine@...>

Bug #2250: IO::for_fd() objects' finalization dangerously closes underlying fds

11 messages 2009/10/22

[#26244] [Bug #2258] Kernel#require inside rb_require() inside rb_protect() inside SysV context fails — Suraj Kurapati <redmine@...>

Bug #2258: Kernel#require inside rb_require() inside rb_protect() inside SysV context fails

24 messages 2009/10/22

[#26361] [Feature #2294] [PATCH] ruby_bind_stack() to embed Ruby in coroutine — Suraj Kurapati <redmine@...>

Feature #2294: [PATCH] ruby_bind_stack() to embed Ruby in coroutine

42 messages 2009/10/27

[#26371] [Bug #2295] segmentation faults — tomer doron <redmine@...>

Bug #2295: segmentation faults

16 messages 2009/10/27

[ruby-core:26131] [Bug #2221] lib/delegate: freeze has odd effects

From: Marc-Andre Lafortune <redmine@...>
Date: 2009-10-16 19:54:16 UTC
List: ruby-core #26131
Issue #2221 has been updated by Marc-Andre Lafortune.


Hi,

On Fri, Oct 16, 2009 at 7:24 AM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> I think both should be frozen.  I checked in the patch.  I'd like to
> see if it works (or not).

Indeed, I thought about it and came to the same conclusion when thinking of other non-trivial classes that would extend Delegate. It was too cold outside my bed though :-)

(a) Just to be sure: SimpleDelegator([1,2,3].freeze).frozen? should return false, right?

(b) Still can't clone it, though.
Is there a nice way to avoid the exception? The best I can think of is the inelegant:

diff --git a/lib/delegate.rb b/lib/delegate.rb
index 5d25632..5ef9c1c 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -188,11 +188,14 @@ class Delegator
     __setobj__(obj)
   end
 
+  alias_method :__original_dup__, :dup
+  private :__original_dup__
+
   # Clone support for the object returned by \_\_getobj\_\_.
   def clone
-    new = super
+    new = frozen? ? __original_dup__ : super
     new.__setobj__(__getobj__.clone)
-    new
+    frozen? ? new.freeze : new
   end
   # Duplication support for the object returned by \_\_getobj\_\_.
   def dup

----------------------------------------
http://redmine.ruby-lang.org/issues/show/2221

----------------------------------------
http://redmine.ruby-lang.org

In This Thread

Prev Next