summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
Diffstat (limited to 'class.c')
-rw-r--r--class.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/class.c b/class.c
index a642ff0029..9ff56f8563 100644
--- a/class.c
+++ b/class.c
@@ -838,11 +838,22 @@ VALUE
rb_mod_ancestors(VALUE mod)
{
VALUE p, ary = rb_ary_new();
+ VALUE origin = RCLASS_ORIGIN(mod);
- for (p = mod; p; p = RCLASS_SUPER(p)) {
+ p = mod;
+ if (origin == mod) {
+ origin = 0;
+ }
+ else {
+ p = RCLASS_SUPER(p);
+ }
+ for (; p; p = RCLASS_SUPER(p)) {
if (FL_TEST(p, FL_SINGLETON))
continue;
- if (BUILTIN_TYPE(p) == T_ICLASS) {
+ if (p == origin) {
+ rb_ary_push(ary, mod);
+ }
+ else if (BUILTIN_TYPE(p) == T_ICLASS) {
rb_ary_push(ary, RBASIC(p)->klass);
}
else {