From 818d6a1e4f145f3ff9a60933f71336a034c59536 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 6 Nov 2003 07:22:39 +0000 Subject: * eval.c (rb_load): allow interrupt during loaded program evaluation. [ruby-dev:21834] * hash.c (rb_hash_fetch): always warn if default argument and a block are supplied at the same time. [ruby-dev:21842] * hash.c (env_fetch): ditto. * array.c (rb_ary_fetch): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- array.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'array.c') diff --git a/array.c b/array.c index ac2bb7d265..ba030bf468 100644 --- a/array.c +++ b/array.c @@ -595,21 +595,21 @@ rb_ary_fetch(argc, argv, ary) VALUE ary; { VALUE pos, ifnone; + long block_given; long idx; rb_scan_args(argc, argv, "11", &pos, &ifnone); + block_given = rb_block_given_p(); + if (block_given && argc == 2) { + rb_warn("block supersedes default value argument"); + } idx = NUM2LONG(pos); if (idx < 0) { idx += RARRAY(ary)->len; } if (idx < 0 || RARRAY(ary)->len <= idx) { - if (rb_block_given_p()) { - if (argc > 1) { - rb_raise(rb_eArgError, "wrong number of arguments"); - } - return rb_yield(pos); - } + if (block_given) return rb_yield(pos); if (argc == 1) { rb_raise(rb_eIndexError, "index %ld out of array", idx); } -- cgit v1.2.3