зеркало из https://github.com/github/ruby.git
* hash.c (rb_hash_flatten): use NUM2INT to raise TypeError on 32bit
platform. it's introduced by r42039 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
32ee210345
Коммит
f262909cba
|
@ -1,3 +1,8 @@
|
|||
Sun Jul 21 03:36:18 2013 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* hash.c (rb_hash_flatten): use NUM2INT to raise TypeError on 32bit
|
||||
platform. it's introduced by r42039
|
||||
|
||||
Sun Jul 21 01:07:45 2013 Benoit Daloze <eregontp@gmail.com>
|
||||
|
||||
* common.mk (help): Fix environment variable name and argument.
|
||||
|
|
2
hash.c
2
hash.c
|
@ -2223,7 +2223,7 @@ rb_hash_flatten(int argc, VALUE *argv, VALUE hash)
|
|||
ary = rb_ary_new_capa(RHASH_SIZE(hash) * 2);
|
||||
rb_hash_foreach(hash, flatten_i, ary);
|
||||
if (argc) {
|
||||
int level = FIX2INT(*argv) - 1;
|
||||
int level = NUM2INT(*argv) - 1;
|
||||
if (level > 0) {
|
||||
*argv = INT2FIX(level);
|
||||
rb_funcall2(ary, rb_intern("flatten!"), argc, argv);
|
||||
|
|
|
@ -879,6 +879,15 @@ class TestHash < Test::Unit::TestCase
|
|||
|
||||
def test_flatten
|
||||
assert_equal([[1], [2]], {[1] => [2]}.flatten)
|
||||
|
||||
a = {1=> "one", 2 => [2,"two"], 3 => [3, ["three"]]}
|
||||
assert_equal([1, "one", 2, [2, "two"], 3, [3, ["three"]]], a.flatten)
|
||||
assert_equal([1, "one", 2, [2, "two"], 3, [3, ["three"]]], a.flatten(-1))
|
||||
assert_equal([1, "one", 2, [2, "two"], 3, [3, ["three"]]], a.flatten(0))
|
||||
assert_equal([1, "one", 2, [2, "two"], 3, [3, ["three"]]], a.flatten(1))
|
||||
assert_equal([1, "one", 2, 2, "two", 3, 3, ["three"]], a.flatten(2))
|
||||
assert_equal([1, "one", 2, 2, "two", 3, 3, "three"], a.flatten(3))
|
||||
assert_raise(TypeError){ a.flatten(Object) }
|
||||
end
|
||||
|
||||
def test_callcc
|
||||
|
|
Загрузка…
Ссылка в новой задаче