Sha256: 5e437e1af962c28a0bbe25a5eba3ffa033bbd020d6e2397e5ea3d9e83f3f62ef

Contents?: true

Size: 500 Bytes

Versions: 2

Compression:

Stored size: 500 Bytes

Contents

# frozen_string_literal: true

module LIT
  # @api public
  # @since 0.1.0
  module ModuleObserver
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
litl-0.1.1 lib/lit/module_observer.rb
litl-0.1.0 lib/lit/module_observer.rb