summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/variable.c b/variable.c
index b37c040681..cd9fe0d48e 100644
--- a/variable.c
+++ b/variable.c
@@ -1167,11 +1167,10 @@ rb_mod_const_of(mod, ary)
VALUE mod;
VALUE ary;
{
- rb_mod_const_at(mod, ary);
for (;;) {
+ rb_mod_const_at(mod, ary);
mod = RCLASS(mod)->super;
if (!mod) break;
- rb_mod_const_at(mod, ary);
}
return ary;
}
@@ -1488,6 +1487,40 @@ rb_define_class_variable(klass, name, val)
rb_cvar_declare(klass, id, val);
}
+static int
+cv_i(key, value, ary)
+ ID key;
+ VALUE value;
+ VALUE ary;
+{
+ if (rb_is_class_id(key)) {
+ VALUE kval = rb_str_new2(rb_id2name(key));
+ if (!rb_ary_includes(ary, kval)) {
+ rb_ary_push(ary, kval);
+ }
+ }
+ return ST_CONTINUE;
+}
+
+VALUE
+rb_mod_class_variables(obj)
+ VALUE obj;
+{
+ VALUE ary = rb_ary_new();
+
+ if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)
+ rb_raise(rb_eSecurityError, "Insecure: can't get metainfo");
+
+ for (;;) {
+ if (RCLASS(obj)->iv_tbl) {
+ st_foreach(RCLASS(obj)->iv_tbl, cv_i, ary);
+ }
+ obj = RCLASS(obj)->super;
+ if (!obj) break;
+ }
+ return ary;
+}
+
VALUE
rb_iv_get(obj, name)
VALUE obj;