1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* array.c (rb_ary_flatten_bang): returns nil if nothing changed.

a patch from Marc-Andre Lafortune in [ruby-core:23382].


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-05-07 07:40:11 +00:00
parent 2f16447239
commit 94ee3e7e02
3 changed files with 9 additions and 1 deletions

View file

@ -1,3 +1,8 @@
Thu May 7 16:40:09 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (rb_ary_flatten_bang): returns nil if nothing changed.
a patch from Marc-Andre Lafortune in [ruby-core:23382].
Thu May 7 14:26:14 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Thu May 7 14:26:14 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (rb_ary_sample): negative sample number is invalid. * array.c (rb_ary_sample): negative sample number is invalid.

View file

@ -3338,7 +3338,7 @@ rb_ary_flatten_bang(int argc, VALUE *argv, VALUE ary)
rb_scan_args(argc, argv, "01", &lv); rb_scan_args(argc, argv, "01", &lv);
if (!NIL_P(lv)) level = NUM2INT(lv); if (!NIL_P(lv)) level = NUM2INT(lv);
if (level == 0) return ary; if (level == 0) return Qnil;
result = flatten(ary, level, &mod); result = flatten(ary, level, &mod);
if (mod == 0) return Qnil; if (mod == 0) return Qnil;

View file

@ -736,11 +736,14 @@ class TestArray < Test::Unit::TestCase
a5 = @cls[ a1, @cls[], a3 ] a5 = @cls[ a1, @cls[], a3 ]
assert_equal(@cls[1, 2, 3, 4, 5, 6], a5.flatten!) assert_equal(@cls[1, 2, 3, 4, 5, 6], a5.flatten!)
assert_nil(a5.flatten!(0), '[ruby-core:23382]')
assert_equal(@cls[1, 2, 3, 4, 5, 6], a5) assert_equal(@cls[1, 2, 3, 4, 5, 6], a5)
assert_equal(@cls[], @cls[].flatten) assert_equal(@cls[], @cls[].flatten)
assert_equal(@cls[], assert_equal(@cls[],
@cls[@cls[@cls[@cls[],@cls[]],@cls[@cls[]],@cls[]],@cls[@cls[@cls[]]]].flatten) @cls[@cls[@cls[@cls[],@cls[]],@cls[@cls[]],@cls[]],@cls[@cls[@cls[]]]].flatten)
assert_nil(@cls[].flatten!(0), '[ruby-core:23382]')
end end
def test_flatten_with_callcc def test_flatten_with_callcc