[macruby-changes] [738] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Nov 12 07:17:15 PST 2008


Revision: 738
          http://trac.macosforge.org/projects/ruby/changeset/738
Author:   ben at tanjero.com
Date:     2008-11-12 07:17:15 -0800 (Wed, 12 Nov 2008)
Log Message:
-----------
Fixed up Set#initialize to match the stdlib version.

Modified Paths:
--------------
    MacRuby/trunk/lib/set.rb
    MacRuby/trunk/set.c

Modified: MacRuby/trunk/lib/set.rb
===================================================================
--- MacRuby/trunk/lib/set.rb	2008-11-12 05:11:28 UTC (rev 737)
+++ MacRuby/trunk/lib/set.rb	2008-11-12 15:17:15 UTC (rev 738)
@@ -54,28 +54,6 @@
 class Set
   include Enumerable
 
-  # Creates a new set containing the given objects.
-#  def self.[](*ary)
-#    new(ary)
-#  end
-#
-#  # Creates a new set containing the elements of the given enumerable
-#  # object.
-#  #
-#  # If a block is given, the elements of enum are preprocessed by the
-#  # given block.
-#  def initialize(enum = nil, &block) # :yields: o
-#    @hash ||= Hash.new
-#
-#    enum.nil? and return
-#
-#    if block
-#      enum.each { |o| add(block[o]) }
-#    else
-#      merge(enum)
-#    end
-#  end
-#
 #  # Copy internal hash.
 #  def initialize_copy(orig)
 #    replace(orig)

Modified: MacRuby/trunk/set.c
===================================================================
--- MacRuby/trunk/set.c	2008-11-12 05:11:28 UTC (rev 737)
+++ MacRuby/trunk/set.c	2008-11-12 15:17:15 UTC (rev 738)
@@ -10,6 +10,7 @@
  */
 
 #include "ruby/ruby.h"
+#include "id.h"
 
 VALUE rb_cSet;
 VALUE rb_cNSSet, rb_cNSMutableSet, rb_cCFSet;
@@ -260,6 +261,7 @@
 static VALUE
 rb_set_each(VALUE set)
 {
+    RETURN_ENUMERATOR(set, 0, 0);
     CFSetApplyFunction((CFMutableSetRef)set, rb_set_each_callback, NULL);
     return Qnil;
 }
@@ -291,6 +293,33 @@
     return CFEqual((CFTypeRef)set, (CFTypeRef)RB2OC(other)) ? Qtrue : Qfalse;
 }
 
+static VALUE
+initialize_i(VALUE val, VALUE *args)
+{
+    if (rb_block_given_p())
+	val = rb_yield(val);
+    rb_set_add((VALUE)args, val);
+
+    return Qnil;
+}
+
+static VALUE
+rb_set_initialize(int argc, VALUE *argv, VALUE set)
+{
+    VALUE val;
+
+    set = (VALUE)objc_msgSend((id)set, selInit);
+
+    rb_scan_args(argc, argv, "01", &val);
+    if (!NIL_P(val)) {
+	rb_block_call(val, rb_intern("each"), 0, 0, initialize_i, (VALUE)set);
+    } else if (rb_block_given_p()) {
+	rb_warning("given block not used");
+    }
+
+    return set;
+}
+
 void
 Init_Set(void)
 {
@@ -306,6 +335,7 @@
 
     rb_define_method(rb_cSet, "dup", rb_set_dup, 0);
     rb_define_method(rb_cSet, "clone", rb_set_clone, 0);
+    rb_define_method(rb_cSet, "initialize", rb_set_initialize, -1);
 
     rb_define_method(rb_cSet, "to_a", rb_set_to_a, 0);
     rb_define_method(rb_cSet, "==", rb_set_equal, 1);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20081112/3e98f7d2/attachment.html>


More information about the macruby-changes mailing list