summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-02-29 08:05:32 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-02-29 08:05:32 +0000
commit4890f3a684aff94d93a5cc3f68fa8c67c1da6c19 (patch)
tree3e43148d3114380fff1418aa3ff6d01b157a97e4 /hash.c
parent0c123a83f0446204d974318b578236c949e5a01f (diff)
2000-02-29
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/hash.c b/hash.c
index 2178246..b7e7516 100644
--- a/hash.c
+++ b/hash.c
@@ -171,47 +171,51 @@ rb_hash_foreach(hash, func, farg)
}
static VALUE
-rb_hash_s_new(argc, argv, klass)
- int argc;
- VALUE *argv;
+rb_hash_new2(klass)
VALUE klass;
{
- VALUE ifnone;
-
NEWOBJ(hash, struct RHash);
OBJSETUP(hash, klass, T_HASH);
hash->iter_lev = 0;
hash->ifnone = Qnil;
hash->tbl = 0; /* avoid GC crashing */
-
- rb_scan_args(argc, argv, "01", &ifnone);
-
- hash->ifnone = ifnone;
hash->tbl = st_init_table(&objhash);
return (VALUE)hash;
}
+VALUE
+rb_hash_new()
+{
+ return rb_hash_new2(rb_cHash);
+}
+
static VALUE
-rb_hash_new2(klass)
+rb_hash_s_new(argc, argv, klass)
+ int argc;
+ VALUE *argv;
VALUE klass;
{
- NEWOBJ(hash, struct RHash);
- OBJSETUP(hash, klass, T_HASH);
+ VALUE hash = rb_hash_new2(klass);
- hash->iter_lev = 0;
- hash->ifnone = Qnil;
- hash->tbl = 0; /* avoid GC crashing */
- hash->tbl = st_init_table(&objhash);
-
- return (VALUE)hash;
+ rb_obj_call_init(hash, argc, argv);
+ return hash;
}
-VALUE
-rb_hash_new()
+static VALUE
+rb_hash_initialize(argc, argv, hash)
+ int argc;
+ VALUE *argv;
+ VALUE hash;
{
- return rb_hash_new2(rb_cHash);
+ VALUE ifnone;
+
+ rb_scan_args(argc, argv, "01", &ifnone);
+ rb_hash_modify(hash);
+ RHASH(hash)->ifnone = ifnone;
+
+ return hash;
}
static VALUE
@@ -1382,6 +1386,7 @@ Init_Hash()
rb_define_singleton_method(rb_cHash, "new", rb_hash_s_new, -1);
rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1);
+ rb_define_method(rb_cHash,"initialize", rb_hash_initialize, -1);
rb_define_method(rb_cHash,"clone", rb_hash_clone, 0);
rb_define_method(rb_cHash,"dup", rb_hash_dup, 0);