Module: Corefines::Support

Defined in:
lib/corefines/support/alias_submodules.rb,
lib/corefines/support/fake_refinements.rb,
lib/corefines/support/classes_including_module.rb

Defined Under Namespace

Modules: AliasSubmodules, FakeRefinements

Class Method Summary collapse

Class Method Details

.classes_including_module(mod) {|Class| ... } ⇒ void

Finds all classes that includes the specified module. Results are cached to speed-up repeated calls.

Parameters:

  • mod (Module)

    the module.

Yields:

  • (Class)

    gives each class that includes the mod.


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/corefines/support/classes_including_module.rb', line 14

def self.classes_including_module(mod)
  @classes_including_module[mod] ||=
    ::ObjectSpace.each_object(::Class).select do |klass|
      begin
        klass.included_modules.include?(mod)
      rescue
        # ignore errors
      end
    end

  @classes_including_module[mod].each { |e| yield e }
end