Module: Expand
- Defined in:
- lib/expand.rb,
lib/expand/version.rb
Overview
Extend your classes or modules to use the Expand methods
Defined Under Namespace
Classes: Manager
Constant Summary collapse
- VERSION =
"1.0.6"
Class Method Summary collapse
-
.expand { ... } ⇒ Expand::Manager
Allows you to open a module namespace to add constants.
-
.namespace(context, **class_or_module) { ... } ⇒ Expand::Manager
Allows you to open a module namespace to add constants.
Class Method Details
.expand { ... } ⇒ Expand::Manager
Allows you to open a module namespace to add constants
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/expand.rb', line 117 def namespace(context, **class_or_module, &block) manager = Manager.for(context) case class_or_module in { module: Symbol => _creating_module, class: Symbol => _creating_class } raise ArgumentError, "You must choose either class: or module: but not both." in { class: Symbol => creating_class, ** } parent = class_or_module[:parent] || Object manager.create_class(creating_class, parent: parent, &block) in { module: Symbol => creating_module, ** } if parent = class_or_module[:parent] warn "An option for :parent was provided as `#{parent}' but was ignored when creating the module: #{creating_module}" end manager.create_module(creating_module, &block) else manager.apply(&block) end end |
.namespace(context, **class_or_module) { ... } ⇒ Expand::Manager
Allows you to open a module namespace to add constants
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/expand.rb', line 97 def namespace(context, **class_or_module, &block) manager = Manager.for(context) case class_or_module in { module: Symbol => _creating_module, class: Symbol => _creating_class } raise ArgumentError, "You must choose either class: or module: but not both." in { class: Symbol => creating_class, ** } parent = class_or_module[:parent] || Object manager.create_class(creating_class, parent: parent, &block) in { module: Symbol => creating_module, ** } if parent = class_or_module[:parent] warn "An option for :parent was provided as `#{parent}' but was ignored when creating the module: #{creating_module}" end manager.create_module(creating_module, &block) else manager.apply(&block) end end |