Revision
810
Author
eloy.de.enige@gmail.com
Date
2009-02-12 11:00:03 -0800 (Thu, 12 Feb 2009)

Log Message

Copy a Hash?\226?\128?\153s default proc when duplicating an instance. Hat-tip to Scott Ford.

Modified Paths

Diff

Modified: MacRuby/trunk/hash.c (809 => 810)


--- MacRuby/trunk/hash.c	2009-01-22 16:31:05 UTC (rev 809)
+++ MacRuby/trunk/hash.c	2009-02-12 19:00:03 UTC (rev 810)
@@ -167,6 +167,11 @@
     if (OBJ_TAINTED(rcv))
 	OBJ_TAINT(dup);
     CFMakeCollectable((CFTypeRef)dup);
+
+	struct rb_objc_hash_struct *s = rb_objc_hash_get_struct(rcv);
+	if (s != NULL)
+	    rb_objc_hash_set_struct(dup, s->ifnone, s->has_proc_default);
+
     return dup;
 }
 

Modified: MacRuby/trunk/test-macruby/cases/hash_test.rb (809 => 810)


--- MacRuby/trunk/test-macruby/cases/hash_test.rb	2009-01-22 16:31:05 UTC (rev 809)
+++ MacRuby/trunk/test-macruby/cases/hash_test.rb	2009-02-12 19:00:03 UTC (rev 810)
@@ -3,7 +3,6 @@
 require File.expand_path('../../test_helper', __FILE__)
 
 class TestHash < Test::Unit::TestCase
-
   def test_hash_class
     assert(Hash.is_a?(Class))
     assert(Hash.ancestors.include?(NSDictionary))
@@ -88,4 +87,8 @@
     assert_equal(nil, h[1])
   end
 
+  it "should return a duplicate _with_ default proc" do
+    hash = Hash.new { |_,k| k }.dup
+    assert_equal :default, hash[:default]
+  end
 end