american-ninja-warrior
american-ninja-warrior

Reputation: 8185

How to search defined constants in ruby

How can I show all defined constants with the word "AjaxDatatablesRails" in it?

I tried this:

::AjaxDatatablesRails::Extensions
# >> NameError: uninitialized constant AjaxDatatablesRails::Extensions

Upvotes: 2

Views: 410

Answers (1)

Tom Lord
Tom Lord

Reputation: 28305

Module.constants.grep /AjaxDatatablesRails/

Module.constants returns an array of the names of all constants accessible from the point of call.

Enumerable#grep then loops through this array, and filters out the names matching the given pattern.

Upvotes: 6

Related Questions