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

array.c: rb_check_to_array

* array.c (rb_check_to_array): conversion to array by to_a method.
  returns nil if not possible.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62072 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-01-27 09:27:47 +00:00
parent 9473f86fb0
commit d0fa578cdc
4 changed files with 11 additions and 4 deletions

View file

@ -655,6 +655,12 @@ rb_check_array_type(VALUE ary)
return rb_check_convert_type_with_id(ary, T_ARRAY, "Array", idTo_ary);
}
VALUE
rb_check_to_array(VALUE ary)
{
return rb_check_convert_type_with_id(ary, T_ARRAY, "Array", idTo_a);
}
/*
* call-seq:
* Array.try_convert(obj) -> array or nil

View file

@ -1059,6 +1059,7 @@ VALUE rb_ary_aref1(VALUE ary, VALUE i);
VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e);
size_t rb_ary_memsize(VALUE);
VALUE rb_to_array_type(VALUE obj);
VALUE rb_check_to_array(VALUE ary);
#if defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
#define rb_ary_new_from_args(n, ...) \
__extension__ ({ \

View file

@ -3595,7 +3595,7 @@ rb_Array(VALUE val)
VALUE tmp = rb_check_array_type(val);
if (NIL_P(tmp)) {
tmp = rb_check_convert_type_with_id(val, T_ARRAY, "Array", idTo_a);
tmp = rb_check_to_array(val);
if (NIL_P(tmp)) {
return rb_ary_new3(1, val);
}

View file

@ -2968,8 +2968,8 @@ static VALUE
vm_concat_array(VALUE ary1, VALUE ary2st)
{
const VALUE ary2 = ary2st;
VALUE tmp1 = rb_check_convert_type_with_id(ary1, T_ARRAY, "Array", idTo_a);
VALUE tmp2 = rb_check_convert_type_with_id(ary2, T_ARRAY, "Array", idTo_a);
VALUE tmp1 = rb_check_to_array(ary1);
VALUE tmp2 = rb_check_to_array(ary2);
if (NIL_P(tmp1)) {
tmp1 = rb_ary_new3(1, ary1);
@ -2988,7 +2988,7 @@ vm_concat_array(VALUE ary1, VALUE ary2st)
static VALUE
vm_splat_array(VALUE flag, VALUE ary)
{
VALUE tmp = rb_check_convert_type_with_id(ary, T_ARRAY, "Array", idTo_a);
VALUE tmp = rb_check_to_array(ary);
if (NIL_P(tmp)) {
return rb_ary_new3(1, ary);
}