diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | hash.c | 12 | ||||
-rw-r--r-- | intern.h | 1 |
3 files changed, 19 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Sat Apr 19 18:42:04 2008 Akinori MUSHA <[email protected]> + + * intern.h, hash.c (rb_hash_lookup): New internal function to + check if a key exists in a hash, ignoring #default; backported + from 1.9. + Fri Apr 18 18:56:57 2008 Akinori MUSHA <[email protected]> * ext/syck/rubyext.c (syck_genericresolver_node_import): should @@ -454,6 +454,18 @@ rb_hash_aref(hash, key) return val; } +VALUE +rb_hash_lookup(hash, key) + VALUE hash, key; +{ + VALUE val; + + if (!st_lookup(RHASH(hash)->tbl, key, &val)) { + return Qnil; /* without Hash#default */ + } + return val; +} + /* * call-seq: * hsh.fetch(key [, default] ) => obj @@ -270,6 +270,7 @@ VALUE rb_hash _((VALUE)); VALUE rb_hash_new _((void)); VALUE rb_hash_freeze _((VALUE)); VALUE rb_hash_aref _((VALUE, VALUE)); +VALUE rb_hash_lookup _((VALUE, VALUE)); VALUE rb_hash_aset _((VALUE, VALUE, VALUE)); VALUE rb_hash_delete_if _((VALUE)); VALUE rb_hash_delete _((VALUE,VALUE)); |