summaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-25 08:22:11 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-25 08:22:11 +0000
commitf4d7f48ef56f3d096fcfb4f48829f022071acac3 (patch)
treebdf1c6377a12f1405ac48b2819ac59fbeb4c12a5 /array.c
parenta143fef2e6888dc3b80d74c123c0af1fd97d2f81 (diff)
downloadruby-f4d7f48ef56f3d096fcfb4f48829f022071acac3.tar.gz
ruby-f4d7f48ef56f3d096fcfb4f48829f022071acac3.tar.xz
ruby-f4d7f48ef56f3d096fcfb4f48829f022071acac3.zip
* class.c (rb_include_module): detect cyclic module inclusion.
* eval.c (rb_thread_cleanup): need not to free thread stacks at process termination. * array.c (rb_ary_fetch): use the block to get the default value if the block is given. * eval.c (rb_thread_schedule): should check time only if BOTH WAIT_SELECT and WAIT_TIME. * eval.c (umethod_bind): should update rklass field. * hash.c (rb_hash_update): if a block is given, yields [key, value1, value2] to the block to resolve conflict. * string.c (rb_str_split_m): no need to consider KANJI characters, if the length of separator is 1 (byte). git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@2015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/array.c b/array.c
index 55ee37ff8..f4ec7070a 100644
--- a/array.c
+++ b/array.c
@@ -550,8 +550,16 @@ rb_ary_fetch(argc, argv, ary)
idx += RARRAY(ary)->len;
}
if (idx < 0 || RARRAY(ary)->len <= idx) {
- if (argc == 2) return ifnone;
- rb_raise(rb_eIndexError, "index %d out of array", idx);
+ if (rb_block_given_p()) {
+ if (argc > 1) {
+ rb_raise(rb_eArgError, "wrong number of arguments");
+ }
+ return rb_yield(pos);
+ }
+ if (argc == 1) {
+ rb_raise(rb_eIndexError, "index %d out of array", idx);
+ }
+ return ifnone;
}
return RARRAY(ary)->ptr[idx];
}