summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-02 08:25:21 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-02 08:25:21 (GMT)
commit255adda52fcd161f62fd75eec9504200e6b6eea8 (patch)
tree37f9398a89e99c83bf5a99da4e836574ff15346f /hash.c
parent18a9926ad992f166cd1287ded00e9b7929c897c3 (diff)
hash.c: use rb_check_arity
* hash.c (rb_hash_initialize, rb_hash_fetch_m, rb_hash_default): use rb_check_arity over rb_scan_args. (env_fetch): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/hash.c b/hash.c
index 348e5fb..4bf0ae3 100644
--- a/hash.c
+++ b/hash.c
@@ -499,7 +499,8 @@ rb_hash_initialize(int argc, VALUE *argv, VALUE hash)
FL_SET(hash, HASH_PROC_DEFAULT);
}
else {
- rb_scan_args(argc, argv, "01", &ifnone);
+ rb_check_arity(argc, 0, 1);
+ ifnone = argc == 0 ? Qnil : argv[0];
RHASH_SET_IFNONE(hash, ifnone);
}
@@ -766,11 +767,12 @@ rb_hash_lookup(VALUE hash, VALUE key)
static VALUE
rb_hash_fetch_m(int argc, VALUE *argv, VALUE hash)
{
- VALUE key, if_none;
+ VALUE key;
st_data_t val;
long block_given;
- rb_scan_args(argc, argv, "11", &key, &if_none);
+ rb_check_arity(argc, 1, 2);
+ key = argv[0];
block_given = rb_block_given_p();
if (block_given && argc == 2) {
@@ -786,7 +788,7 @@ rb_hash_fetch_m(int argc, VALUE *argv, VALUE hash)
desc = rb_str_ellipsize(desc, 65);
rb_raise(rb_eKeyError, "key not found: %"PRIsVALUE, desc);
}
- return if_none;
+ return argv[1];
}
return (VALUE)val;
}
@@ -823,7 +825,8 @@ rb_hash_default(int argc, VALUE *argv, VALUE hash)
{
VALUE key, ifnone;
- rb_scan_args(argc, argv, "01", &key);
+ rb_check_arity(argc, 0, 1);
+ key = argv[0];
ifnone = RHASH_IFNONE(hash);
if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
if (argc == 0) return Qnil;
@@ -2637,11 +2640,12 @@ rb_f_getenv(VALUE obj, VALUE name)
static VALUE
env_fetch(int argc, VALUE *argv)
{
- VALUE key, if_none;
+ VALUE key;
long block_given;
const char *nam, *env;
- rb_scan_args(argc, argv, "11", &key, &if_none);
+ rb_check_arity(argc, 1, 2);
+ key = argv[0];
block_given = rb_block_given_p();
if (block_given && argc == 2) {
rb_warn("block supersedes default value argument");
@@ -2653,7 +2657,7 @@ env_fetch(int argc, VALUE *argv)
if (argc == 1) {
rb_raise(rb_eKeyError, "key not found: \"%"PRIsVALUE"\"", key);
}
- return if_none;
+ return argv[1];
}
if (ENVMATCH(nam, PATH_ENV) && !env_path_tainted(env))
return env_path_str_new(env);