I found an interesting but unexplained alternative to an accepted answer. The code clearly works in the REPL. For example:
module
&Foo.method(:const_get)
is the method const_get
of the Foo
object. Here's another example:
m = 1.method(:+)
#=> #
m.call(1)
#=> 2
(1..3).map(&m)
#=> [2, 3, 4]
So in the end this is just a pointfree way of saying Foo.constants.map { |c| Foo.const_get(c) }
. grep
uses ===
to select elements, so it would only get constants that refer to classes, not other values. This can be verified by adding another constant to Foo
, e.g. Baz = 1
, which will not get grep
ped.
If you have further questions please add them as comments and I'll try to clarify them.