Module: LIT::ModuleObserver

Defined in:
lib/lit/module_observer.rb

Overview

Since:

  • 0.1.0

Class Method Summary collapse

Class Method Details

.included(object) ⇒ Object

Since:

  • 0.1.0



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/lit/module_observer.rb', line 7

def self.included(object)
  object.define_singleton_method(:observe) do |target_module|
    namespace = target_module.name.split("::")

    define_singleton_method(:const_missing) do |const_name|
      mod = namespace.reduce(self) do |mod, child_name|
        mod.const_get(child_name)
      end

      mod.const_get(const_name)
    end
  end
end