diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-03-29 02:56:18 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-03-29 02:56:18 +0000 |
commit | fec60bc7c4f851d0cf1c4670ef8f2d9c597b7598 (patch) | |
tree | fe375a324a27f43bd07a192814a516ee99557656 /eval.c | |
parent | 95785964f693e4af9b93513dce3960ebc5aab452 (diff) |
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@3633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 74 |
1 files changed, 49 insertions, 25 deletions
@@ -2201,42 +2201,47 @@ static VALUE avalue_to_svalue(v) VALUE v; { - if (TYPE(v) != T_ARRAY) { + VALUE tmp, top; + + tmp = rb_check_array_type(v); + if (NIL_P(v)) { return v; } - if (RARRAY(v)->len == 0) { + if (RARRAY(tmp)->len == 0) { return Qundef; } - if (RARRAY(v)->len == 1) { - VALUE tmp = RARRAY(v)->ptr[0]; - if (TYPE(tmp) != T_ARRAY) { - return tmp; + if (RARRAY(tmp)->len == 1) { + top = rb_check_array_type(RARRAY(tmp)->ptr[0]); + if (NIL_P(top)) { + return RARRAY(tmp)->ptr[0]; } - if (RARRAY(tmp)->len > 1) { + if (RARRAY(top)->len > 1) { return v; } - return tmp; + return top; } - return v; + return tmp; } static VALUE svalue_to_avalue(v) VALUE v; { - VALUE tmp; + VALUE tmp, top; if (v == Qundef) return rb_ary_new2(0); - if (TYPE(v) != T_ARRAY) { + tmp = rb_check_array_type(v); + if (NIL_P(tmp)) { return rb_ary_new3(1, v); } - if (RARRAY(v)->len == 1) { - tmp = RARRAY(v)->ptr[0]; - if (TYPE(tmp) == T_ARRAY && RARRAY(tmp)->len > 1) + if (RARRAY(tmp)->len == 1) { + top = rb_check_array_type(RARRAY(tmp)->ptr[0]); + if (!NIL_P(top) && RARRAY(top)->len > 1) { return v; + } return rb_ary_new3(1, v); } - return v; + return tmp; } static VALUE @@ -2257,15 +2262,18 @@ svalue_to_mrhs(v, lhs) VALUE v; NODE *lhs; { + VALUE tmp; + if (v == Qundef) return rb_ary_new2(0); - if (TYPE(v) != T_ARRAY) { + tmp = rb_check_array_type(v); + if (NIL_P(tmp)) { return rb_ary_new3(1, v); } /* no lhs means splat lhs only */ - if (!lhs && RARRAY(v)->len <= 1) { + if (!lhs && RARRAY(tmp)->len <= 1) { return rb_ary_new3(1, v); } - return v; + return tmp; } static VALUE @@ -2652,15 +2660,31 @@ rb_eval(self, n) break; case NODE_SPLAT: - { - VALUE tmp; - - result = rb_eval(self, node->nd_head); - tmp = rb_check_array_type(result); - if (!NIL_P(tmp)) { - result = avalue_splat(tmp); +#if 0 + /* simplified version after Object#to_a removed */ + result = rb_eval(self, node->nd_head); + if (NIL_P(result)) result = rb_ary_new3(1, Qnil); + result = avalue_splat(rb_Array(result)); +#else + result = rb_eval(self, node->nd_head); + if (NIL_P(result)) result = rb_ary_new3(1, Qnil); + if (TYPE(result) != T_ARRAY) { + VALUE tmp = rb_check_array_type(result); + if (NIL_P(tmp)) { + VALUE origin; + ID id = rb_intern("to_a"); + + if (search_method(CLASS_OF(result), id, &origin) && + origin != RCLASS(rb_cObject)->super) { /* exclude Object#to_a */ + result = rb_funcall(result, id, 0); + } + else { + result = rb_ary_new3(1, result); + } } } + result = avalue_splat(rb_Array(result)); +#endif break; case NODE_SVALUE: |