summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2016-05-12 16:52:34 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-09-07 20:08:01 +0900
commitf4d5273989ae8d6569a62b126b2774706b86fbf5 (patch)
tree363d8211b350a925b03270c4090e2075fe3c8fc1 /random.c
parent19917d45a35ff86b3976267b6cb2b494b6130045 (diff)
Random::Base
* random.c (InitVM_Random): introduce abstract super class Random::Base.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3024
Diffstat (limited to 'random.c')
-rw-r--r--random.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/random.c b/random.c
index d213f69..2a3b0d2 100644
--- a/random.c
+++ b/random.c
@@ -1554,14 +1554,21 @@ rb_reset_random_seed(void)
void
InitVM_Random(void)
{
+ VALUE base;
+ ID id_base = rb_intern_const("Base");
+
rb_define_global_function("srand", rb_f_srand, -1);
rb_define_global_function("rand", rb_f_rand, -1);
- rb_cRandom = rb_define_class("Random", rb_cObject);
+ base = rb_define_class_id(id_base, rb_cObject);
+ rb_undef_alloc_func(base);
+ rb_cRandom = rb_define_class("Random", base);
+ rb_const_set(rb_cRandom, id_base, base);
+ rb_set_class_path(base, rb_cRandom, "Base");
rb_define_alloc_func(rb_cRandom, random_alloc);
- rb_define_method(rb_cRandom, "initialize", random_init, -1);
- rb_define_method(rb_cRandom, "rand", random_rand, -1);
- rb_define_method(rb_cRandom, "bytes", random_bytes, 1);
+ rb_define_method(base, "initialize", random_init, -1);
+ rb_define_method(base, "rand", random_rand, -1);
+ rb_define_method(base, "bytes", random_bytes, 1);
rb_define_method(rb_cRandom, "seed", random_get_seed, 0);
rb_define_method(rb_cRandom, "initialize_copy", random_copy, 1);
rb_define_private_method(rb_cRandom, "marshal_dump", random_dump, 0);
@@ -1589,8 +1596,8 @@ InitVM_Random(void)
{
/* Format raw random number as Random does */
VALUE m = rb_define_module_under(rb_cRandom, "Formatter");
- rb_include_module(rb_cRandom, m);
- rb_extend_object(rb_cRandom, m);
+ rb_include_module(base, m);
+ rb_extend_object(base, m);
rb_define_method(m, "random_number", rand_random_number, -1);
rb_define_method(m, "rand", rand_random_number, -1);
}