mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* enum.c (enum_to_a): fix incompatibility introduced in r50457.
[Bug #11130] * test/ruby/test_enum.rb: test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
87944f8e61
commit
95f54fb019
3 changed files with 40 additions and 3 deletions
|
@ -1,3 +1,10 @@
|
|||
Tue May 12 22:18:27 2015 Masaki Matsushita <glass.saga@gmail.com>
|
||||
|
||||
* enum.c (enum_to_a): fix incompatibility introduced in r50457.
|
||||
[Bug #11130]
|
||||
|
||||
* test/ruby/test_enum.rb: test for above.
|
||||
|
||||
Tue May 12 17:08:03 2015 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* method.h: remove unused declaration.
|
||||
|
|
6
enum.c
6
enum.c
|
@ -517,11 +517,11 @@ enum_to_a(int argc, VALUE *argv, VALUE obj)
|
|||
{
|
||||
VALUE ary, size = rb_check_funcall(obj, id_size, 0, 0);
|
||||
|
||||
if (NIL_P(size) || size == Qundef) {
|
||||
ary = rb_ary_new();
|
||||
if (FIXNUM_P(size)) {
|
||||
ary = rb_ary_new_capa(NUM2LONG(size));
|
||||
}
|
||||
else {
|
||||
ary = rb_ary_new_capa(NUM2LONG(size));
|
||||
ary = rb_ary_new();
|
||||
}
|
||||
|
||||
rb_block_call(obj, id_each, argc, argv, collect_all, ary);
|
||||
|
|
|
@ -100,6 +100,36 @@ class TestEnumerable < Test::Unit::TestCase
|
|||
assert_equal([1, 2, 3, 1, 2], @obj.to_a)
|
||||
end
|
||||
|
||||
def test_to_a_size_symbol
|
||||
sym = Object.new
|
||||
class << sym
|
||||
include Enumerable
|
||||
def each
|
||||
self
|
||||
end
|
||||
|
||||
def size
|
||||
:size
|
||||
end
|
||||
end
|
||||
assert_equal([], sym.to_a)
|
||||
end
|
||||
|
||||
def test_to_a_size_infinity
|
||||
inf = Object.new
|
||||
class << inf
|
||||
include Enumerable
|
||||
def each
|
||||
self
|
||||
end
|
||||
|
||||
def size
|
||||
Float::INFINITY
|
||||
end
|
||||
end
|
||||
assert_equal([], inf.to_a)
|
||||
end
|
||||
|
||||
def test_to_h
|
||||
obj = Object.new
|
||||
def obj.each(*args)
|
||||
|
|
Loading…
Add table
Reference in a new issue