summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-05-27 09:31:53 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-05-27 09:31:53 +0000
commita8382af43a39aa1e442861240506559157921288 (patch)
tree729b6675352f2fb436bbd97e67032bcf851cb04e /hash.c
parent18477557236646240da157ed7d53da4998d3fc35 (diff)
*** empty log message ***
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index dd01aa1..59f157b 100644
--- a/hash.c
+++ b/hash.c
@@ -341,6 +341,29 @@ hash_aref(hash, key)
}
static VALUE
+hash_fetch(argc, argv, hash)
+ int argc;
+ VALUE *argv;
+ VALUE hash;
+{
+ VALUE key, if_none;
+ VALUE val;
+
+ rb_scan_args(argc, argv, "11", &key, &if_none);
+
+ if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
+ if (iterator_p()) {
+ if (argc > 1) {
+ ArgError("wrong # of arguments", argc);
+ }
+ return rb_yield(argv[0]);
+ }
+ return if_none;
+ }
+ return val;
+}
+
+static VALUE
hash_indexes(argc, argv, hash)
int argc;
VALUE *argv;
@@ -1159,7 +1182,9 @@ Init_Hash()
rb_define_method(cHash,"==", hash_equal, 1);
rb_define_method(cHash,"[]", hash_aref, 1);
+ rb_define_method(cHash,"fetch", hash_fetch, -1);
rb_define_method(cHash,"[]=", hash_aset, 2);
+ rb_define_method(cHash,"store", hash_aset, 2);
rb_define_method(cHash,"indexes", hash_indexes, -1);
rb_define_method(cHash,"indices", hash_indexes, -1);
rb_define_method(cHash,"length", hash_length, 0);