mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c (take_items): to_ary() raises ArgumentError if cannot to
convert to Array. [ruby-dev:37797] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3b817f834a
commit
6ff613fc09
4 changed files with 15 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
|||
Wed Jan 21 14:41:48 2009 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* array.c (take_items): to_ary() raises ArgumentError if cannot to
|
||||
convert to Array. [ruby-dev:37797]
|
||||
|
||||
Wed Jan 21 14:32:02 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* parse.y (debug_lines): calls rb_intern() once.
|
||||
|
|
2
array.c
2
array.c
|
@ -2209,7 +2209,7 @@ take_i(VALUE val, VALUE *args, int argc, VALUE *argv)
|
|||
static VALUE
|
||||
take_items(VALUE obj, long n)
|
||||
{
|
||||
VALUE result = to_ary(obj);
|
||||
VALUE result = rb_check_array_type(obj);
|
||||
VALUE args[2];
|
||||
|
||||
if (!NIL_P(result)) return rb_ary_subseq(result, 0, n);
|
||||
|
|
|
@ -1505,8 +1505,11 @@ class TestArray < Test::Unit::TestCase
|
|||
|
||||
ary = Object.new
|
||||
def ary.to_a; [1, 2]; end
|
||||
def ary.to_ary; [3, 4]; end
|
||||
assert_equal([[5, 3], [6, 4]], [5, 6].zip(ary))
|
||||
assert_raise(NoMethodError){ %w(a b).zip(ary) }
|
||||
def ary.each; [3, 4].each{|e|yield e}; end
|
||||
assert_equal([['a', 3], ['b', 4]], %w(a b).zip(ary))
|
||||
def ary.to_ary; [5, 6]; end
|
||||
assert_equal([['a', 5], ['b', 6]], %w(a b).zip(ary))
|
||||
end
|
||||
|
||||
def test_transpose
|
||||
|
|
|
@ -214,8 +214,11 @@ class TestEnumerable < Test::Unit::TestCase
|
|||
|
||||
ary = Object.new
|
||||
def ary.to_a; [1, 2]; end
|
||||
def ary.to_ary; [3, 4]; end
|
||||
assert_raise(NoMethodError){ %w(a b).zip(ary) }
|
||||
def ary.each; [3, 4].each{|e|yield e}; end
|
||||
assert_equal([[1, 3], [2, 4], [3, nil], [1, nil], [2, nil]], @obj.zip(ary))
|
||||
def ary.to_ary; [5, 6]; end
|
||||
assert_equal([[1, 5], [2, 6], [3, nil], [1, nil], [2, nil]], @obj.zip(ary))
|
||||
end
|
||||
|
||||
def test_take
|
||||
|
|
Loading…
Reference in a new issue