summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-19 08:22:45 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-19 08:22:45 +0000
commit63219d8a2416f75861fb93d107b1efd213829786 (patch)
treec182a1fc65de2b4cc91756560a12aa8b202cb9c1 /hash.c
parente5bfdb8391b3232c2b682e7eb19e99d85c3c1e9e (diff)
* io.c (rb_io_extract_encoding_option): "internal_encoding: nil"
to specify no-transcoding. and other corner case fixed. [ruby-dev:37496] * hash.c (rb_hash_lookup2): new function to look-up hash with default value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/hash.c b/hash.c
index f3bd0b66b8..b01c4184be 100644
--- a/hash.c
+++ b/hash.c
@@ -463,16 +463,22 @@ rb_hash_aref(VALUE hash, VALUE key)
}
VALUE
-rb_hash_lookup(VALUE hash, VALUE key)
+rb_hash_lookup2(VALUE hash, VALUE key, VALUE def)
{
VALUE val;
if (!RHASH(hash)->ntbl || !st_lookup(RHASH(hash)->ntbl, key, &val)) {
- return Qnil; /* without Hash#default */
+ return def; /* without Hash#default */
}
return val;
}
+VALUE
+rb_hash_lookup(VALUE hash, VALUE key)
+{
+ return rb_hash_lookup2(hash, key, Qnil);
+}
+
/*
* call-seq:
* hsh.fetch(key [, default] ) => obj