Revision
813
Author
lsansonetti@apple.com
Date
2009-02-13 16:56:22 -0800 (Fri, 13 Feb 2009)

Log Message

make sure the primitive methods are added when creating the singleton class of a CF string/array/hash

Modified Paths

Diff

Modified: MacRuby/trunk/class.c (812 => 813)


--- MacRuby/trunk/class.c	2009-02-12 19:06:06 UTC (rev 812)
+++ MacRuby/trunk/class.c	2009-02-14 00:56:22 UTC (rev 813)
@@ -173,7 +173,17 @@
 rb_objc_create_class(const char *name, VALUE super)
 {
     VALUE klass;
-    
+
+    if (super == rb_cCFString) {
+	super = rb_cNSMutableString;
+    }
+    else if (super == rb_cCFArray) {
+	super = rb_cNSMutableArray;
+    }
+    else if (super == rb_cCFHash) {
+	super = rb_cNSMutableHash;
+    }
+
     klass = rb_objc_alloc_class(name, super, T_CLASS, rb_cClass);
     objc_registerClassPair((Class)klass);
    

Modified: MacRuby/trunk/test/ruby/test_array.rb (812 => 813)


--- MacRuby/trunk/test/ruby/test_array.rb	2009-02-12 19:06:06 UTC (rev 812)
+++ MacRuby/trunk/test/ruby/test_array.rb	2009-02-14 00:56:22 UTC (rev 813)
@@ -1584,4 +1584,13 @@
   def test_array_subclass
     assert_equal(Array2, Array2[1,2,3].uniq.class, "[ruby-dev:34581]")
   end
+
+  def test_array_singleton_class
+    a = [1,2,3]
+    def a.foo; 42; end
+    assert_equal(42, a.foo)
+    assert_equal([1,2,3], a)
+    a.replace([4,5,6])
+    assert_equal([4,5,6], a)
+  end
 end