[macruby-changes] [1899] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Fri Jun 19 20:52:27 PDT 2009


Revision: 1899
          http://trac.macosforge.org/projects/ruby/changeset/1899
Author:   lsansonetti at apple.com
Date:     2009-06-19 20:52:27 -0700 (Fri, 19 Jun 2009)
Log Message:
-----------
Boxed#to_a: implemented

Modified Paths:
--------------
    MacRuby/branches/experimental/bridgesupport.cpp
    MacRuby/branches/experimental/spec/macruby/core/struct_spec.rb

Modified: MacRuby/branches/experimental/bridgesupport.cpp
===================================================================
--- MacRuby/branches/experimental/bridgesupport.cpp	2009-06-20 02:41:50 UTC (rev 1898)
+++ MacRuby/branches/experimental/bridgesupport.cpp	2009-06-20 03:52:27 UTC (rev 1899)
@@ -348,6 +348,7 @@
     VALUE *rcv_data;
     Data_Get_Struct(rcv, VALUE, rcv_data);
     rb_vm_bs_boxed_t *bs_boxed = locate_bs_boxed(CLASS_OF(rcv), true);
+
     for (unsigned i = 0; i < bs_boxed->as.s->fields_count; i++) {
 	rb_str_cat2(str, " ");
 	rb_str_cat2(str, bs_boxed->as.s->fields[i].name);
@@ -361,6 +362,22 @@
 }
 
 static VALUE
+rb_vm_struct_to_a(VALUE rcv, SEL sel)
+{
+    VALUE ary = rb_ary_new();
+
+    VALUE *rcv_data;
+    Data_Get_Struct(rcv, VALUE, rcv_data);
+    rb_vm_bs_boxed_t *bs_boxed = locate_bs_boxed(CLASS_OF(rcv), true);
+
+    for (unsigned i = 0; i < bs_boxed->as.s->fields_count; i++) {
+	rb_ary_push(ary, rcv_data[i]);
+    }
+
+    return ary;
+}
+
+static VALUE
 rb_vm_struct_dup(VALUE rcv, SEL sel)
 {
     VALUE klass = CLASS_OF(rcv);
@@ -460,6 +477,8 @@
 		(void *)rb_vm_struct_dup, 0);
 	rb_objc_define_method(boxed->klass, "inspect",
 		(void *)rb_vm_struct_inspect, 0);
+	rb_objc_define_method(boxed->klass, "to_a",
+		(void *)rb_vm_struct_to_a, 0);
     }
     else {
 	// Opaque methods.

Modified: MacRuby/branches/experimental/spec/macruby/core/struct_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/macruby/core/struct_spec.rb	2009-06-20 02:41:50 UTC (rev 1898)
+++ MacRuby/branches/experimental/spec/macruby/core/struct_spec.rb	2009-06-20 03:52:27 UTC (rev 1899)
@@ -212,4 +212,17 @@
     NSSize.object_id.should == CGSize.object_id
     NSRect.object_id.should == CGRect.object_id
   end
+
+  it "returns an Array based on its elements when #to_s is called" do
+    p = NSPoint.new(1, 2)
+    o = p.to_a
+    o.class.should == Array
+    o.should == [1, 2]
+
+    r = NSRect.new(NSPoint.new(1, 2), NSSize.new(3, 4))
+    o = r.to_a
+    o.class.should == Array
+    o.should == [NSPoint.new(1, 2), NSSize.new(3, 4)]
+    o.map { |x| x.to_a }.flatten.should == [1, 2, 3, 4]
+  end
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090619/43d8ec18/attachment.html>


More information about the macruby-changes mailing list