summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-11-06 07:22:39 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-11-06 07:22:39 +0000
commit818d6a1e4f145f3ff9a60933f71336a034c59536 (patch)
tree277366327de60bb4c1132c3117fe90a46cd3aa44 /hash.c
parent113423bdff9c888195c6e22949d5d7f849a05b04 (diff)
* 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
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/hash.c b/hash.c
index 2743ad0e24..75c07797d3 100644
--- a/hash.c
+++ b/hash.c
@@ -300,16 +300,16 @@ rb_hash_fetch(argc, argv, hash)
{
VALUE key, if_none;
VALUE val;
+ long block_given;
rb_scan_args(argc, argv, "11", &key, &if_none);
+ block_given = rb_block_given_p();
+ if (block_given && argc == 2) {
+ rb_warn("block supersedes default value argument");
+ }
if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
- if (rb_block_given_p()) {
- if (argc > 1) {
- rb_raise(rb_eArgError, "wrong number of arguments");
- }
- return rb_yield(key);
- }
+ if (block_given) return rb_yield(key);
if (argc == 1) {
rb_raise(rb_eIndexError, "key not found");
}
@@ -1086,9 +1086,14 @@ env_fetch(argc, argv)
VALUE *argv;
{
VALUE key, if_none;
+ long block_given;
char *nam, *env;
rb_scan_args(argc, argv, "11", &key, &if_none);
+ block_given = rb_block_given_p();
+ if (block_given && argc == 2) {
+ rb_warn("block supersedes default value argument");
+ }
StringValue(key);
nam = RSTRING(key)->ptr;
if (strlen(nam) != RSTRING(key)->len) {
@@ -1096,12 +1101,7 @@ env_fetch(argc, argv)
}
env = getenv(nam);
if (!env) {
- if (rb_block_given_p()) {
- if (argc > 1) {
- rb_raise(rb_eArgError, "wrong number of arguments");
- }
- return rb_yield(key);
- }
+ if (block_given) return rb_yield(key);
if (argc == 1) {
rb_raise(rb_eIndexError, "key not found");
}