summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-19 12:12:03 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-19 12:12:03 +0000
commite4963224156345c75601311518b32505ac1eb060 (patch)
treeb38fdbfdda435026a4a4b5f0514b19592cd1f641 /hash.c
parentea85c2968fbf51836b4176d3f047cd8a76aeab90 (diff)
downloadruby-e4963224156345c75601311518b32505ac1eb060.tar.gz
ruby-e4963224156345c75601311518b32505ac1eb060.tar.xz
ruby-e4963224156345c75601311518b32505ac1eb060.zip
merges r20870 from trunk into ruby_1_9_1.
* 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: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@20886 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 044964c80..a058a00a9 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