Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/modulation/ext.rb
Overview
Module extensions
Instance Method Summary collapse
-
#alias_method_once(new_name, old_name) ⇒ Module
Aliases the given method only if the alias does not exist, implementing in effect idempotent method aliasing.
-
#auto_import(sym, path = nil, caller_location = caller(CALLER_RANGE).first) ⇒ void
Registers a constant to be lazy-loaded upon lookup.
-
#extend_from(path) ⇒ void
Extends the receiver with exported methods from the given file name.
-
#include_from(path, *symbols) ⇒ void
Includes exported methods from the given file name in the receiver The module’s methods will be available as instance methods.
- #setup_auto_import_registry ⇒ Object
Instance Method Details
#alias_method_once(new_name, old_name) ⇒ Module
Aliases the given method only if the alias does not exist, implementing in effect idempotent method aliasing
87 88 89 90 91 |
# 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) ⇒ void
This method returns an undefined value.
Registers a constant to be lazy-loaded upon lookup
45 46 47 48 49 50 51 52 |
# 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) ⇒ void
This method returns an undefined value.
Extends the receiver with exported methods from the given file name
65 66 67 68 69 |
# 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.singleton_class) Modulation::Builder.add_module_constants(mod, self) end |
#include_from(path, *symbols) ⇒ void
This method returns an undefined value.
Includes exported methods from the given file name in the receiver The module’s methods will be available as instance methods
76 77 78 79 80 |
# 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 ⇒ Object
54 55 56 57 58 59 60 |
# 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 |