From: James Edward Gray II Date: 2010-02-02T06:55:26+09:00 Subject: Re: Module children On Feb 1, 2010, at 3:38 PM, Ryan Davis wrote: > > On Feb 1, 2010, at 13:06 , Aaron Patterson wrote: > >> On Tue, Feb 02, 2010 at 04:50:34AM +0900, Camille Roux wrote: >>> Hello, >>> >>> I'd like to get the list of all the classes contained in a module. >>> What's the simple way to do that? >> >>>> module Foo; A = 1; class B; end; module C; end end >> => nil >>>> Foo.constants.find_all { |k| Class === Foo.const_get(k) } >> => ["B"] > > Personally, I usually map first: > >>> Foo.constants.map { |s| Foo.const_get s }.find_all { |k| Class === k } > => [Foo::B] Then you can switch the the under loved grep(): >> Foo.constants.map { |s| Foo.const_get s }.grep(Class) => [Foo::B] James Edward Gray II