From 6d9e428bc560aef1c552a5a5e9db3d606febb6ab Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 29 Mar 2003 02:56:18 +0000 Subject: * eval.c (avalue_to_svalue): use rb_check_array_type() again. Clarify how "to_ary" and "to_a" work. [ruby-talk:68155] * eval.c (svalue_to_avalue): ditto. * eval.c (svalue_to_mrhs): ditto. * eval.c (rb_eval): unary splat to use to_a, but we need a hack to exclude Object#to_a until it's removed. * object.c (rb_Array): check obj.respond_to?("to_a"). Currently all object respond_to "to_a", but Object#to_a will be removed. * range.c (Init_Range): undefine to_ary. * re.c (Init_Regexp): ditto. * regex.c (re_compile_pattern): do not warn if "-" is at the top or last of character class. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 6694e2f8f..69e99f60b 100644 --- a/object.c +++ b/object.c @@ -1270,10 +1270,16 @@ rb_Array(val) val = rb_funcall(val, to_ary, 0); } else { - val = rb_funcall(val, rb_intern("to_a"), 0); + to_ary = rb_intern("to_a"); + if (rb_respond_to(val, to_ary)) { + val = rb_funcall(val, to_ary, 0); + } + else { + val = rb_ary_new3(1, val); + } } if (TYPE(val) != T_ARRAY) { - rb_raise(rb_eTypeError, "`to_a' did not return Array"); + rb_raise(rb_eTypeError, "`%s' did not return Array", rb_id2name(to_ary)); } return val; } -- cgit