[macruby-changes] [5018] MacRuby/trunk/array.c

source_changes at macosforge.org source_changes at macosforge.org
Mon Dec 13 08:36:29 PST 2010


Revision: 5018
          http://trac.macosforge.org/projects/ruby/changeset/5018
Author:   watson1978 at gmail.com
Date:     2010-12-13 08:36:22 -0800 (Mon, 13 Dec 2010)
Log Message:
-----------
Even if Array is empty, when given a block, Array#product will return a self.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

ary = []
ret = ary.product([3,4,5],[6,8]) {}
assert_equal(ary, ret)
assert_equal(ary.object_id, ret.object_id)

ret = ary.product([3,4,5],[6,8])
assert_equal(ary, ret)
assert_not_equal(ary.object_id, ret.object_id)

puts :ok
}}}

Modified Paths:
--------------
    MacRuby/trunk/array.c

Modified: MacRuby/trunk/array.c
===================================================================
--- MacRuby/trunk/array.c	2010-12-13 08:25:10 UTC (rev 5017)
+++ MacRuby/trunk/array.c	2010-12-13 16:36:22 UTC (rev 5018)
@@ -3431,7 +3431,12 @@
     /* Compute the length of the result array; return [] if any is empty */
     for (i = 0; i < n; i++) {
 	long k = RARRAY_LEN(arrays[i]), l = resultlen;
-	if (k == 0) return rb_ary_new2(0);
+	if (k == 0) {
+	    if (rb_block_given_p()) {
+		return ary;
+	    }
+	    return rb_ary_new2(0);
+	}
 	resultlen *= k;
 	if (resultlen < k || resultlen < l || resultlen / k != l) {
 	    rb_raise(rb_eRangeError, "too big to product");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101213/b12149d5/attachment.html>


More information about the macruby-changes mailing list