How to get all class names in a namespace in Ruby?

前端 未结 4 950
挽巷
挽巷 2020-12-28 12:59

I have a module Foo, that it is the namespace for many classes like Foo::Bar, Foo::Baz and so on.

Is there an way to return al

4条回答
  •  萌比男神i
    2020-12-28 13:25

    If, instead of the names of the constants, you want the classes themselves, you could do it like this:

    Foo.constants.map(&Foo.method(:const_get)).grep(Class)
    

提交回复
热议问题