Forum: Ruby on Rails subclasses_of - why does it ignore subclasses within modules

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2f46d76f0e5db4dc318b03be07ebaac4?d=identicon&s=25 Tom Ward (Guest)
on 2006-01-18 12:24
(Received via mailing list)
ActiveSupport provides a method Object.subclasses_of, to give the
subclasses of a given class.  However, it ignores any subclass within
a module, so :

class A
end

class B < A
end

Object.subclasses_of(A) # returns [B]

module C
  class D < A
  end
end

Object.subclasses_of(A) # returns [B], even though C::D is also a
subclass of A

class E < C::D
end

Object.subclasses_of(A) # returns [B, E], even though C::D isn't
returned

This behaviour has been very deliberately built into the code, but
seems to be plainly wrong.  Can anyone provide any insight why this is
so?

Tom
This topic is locked and can not be replied to.