class Module

Module extensions

Public Instance Methods

alias_method_once(new_name, old_name) click to toggle source

Aliases the given method only if the alias does not exist, implementing in effect idempotent method aliasing @param new_name [Symbol] alias name @param old_name [Symbol] original name @return [Module] self

# File lib/modulation/ext.rb, line 87
def alias_method_once(new_name, old_name)
  return self if method_defined?(new_name)

  alias_method(new_name, old_name)
end
auto_import(sym, path = nil, caller_location = caller(CALLER_RANGE).first) click to toggle source

Registers a constant to be lazy-loaded upon lookup @param sym [Symbol, Hash] constant name or hash mapping names to paths @param path [String] path if sym is Symbol @return [void]

# File lib/modulation/ext.rb, line 45
def auto_import(sym, path = nil, caller_location = caller(CALLER_RANGE).first)
  setup_auto_import_registry unless @__auto_import_registry
  if path
    @__auto_import_registry[sym] = [path, caller_location]
  else
    sym.each { |k, v| @__auto_import_registry[k] = [v, caller_location] }
  end
end
extend_from(path) click to toggle source

Extends the receiver with exported methods from the given file name @param path [String] module filename @return [void]

# File lib/modulation/ext.rb, line 65
def extend_from(path)
  mod = import(path, caller(CALLER_RANGE).first)
  Modulation::Builder.add_module_methods(mod, self.class)
  Modulation::Builder.add_module_constants(mod, self)
end
include_from(path, *symbols) click to toggle source

Includes exported methods from the given file name in the receiver The module's methods will be available as instance methods @param path [String] module filename @param symbols [Array<Symbol>] list of symbols to include @return [void]

# File lib/modulation/ext.rb, line 76
def include_from(path, *symbols)
  mod = import(path, caller(CALLER_RANGE).first)
  Modulation::Builder.add_module_methods(mod, self, *symbols)
  Modulation::Builder.add_module_constants(mod, self, *symbols)
end
setup_auto_import_registry() click to toggle source
# File lib/modulation/ext.rb, line 54
def setup_auto_import_registry
  @__auto_import_registry = {}
  Modulation::Builder.define_auto_import_const_missing_method(
    self,
    @__auto_import_registry
  )
end