Module: Ordinary::Module
- Defined in:
- lib/ordinary/module.rb
Defined Under Namespace
Classes: Requirements
Instance Attribute Summary collapse
-
#requirements ⇒ Ordinary::Module::Requirements
readonly
Libraries that the module requires.
Instance Method Summary collapse
-
#requires(*libraries) ⇒ Object
Add libraries to the requirements.
-
#unit(name, unit = nil) {|value, *args| ... } ⇒ Object
Define an unit for some normalizer.
Instance Attribute Details
#requirements ⇒ Ordinary::Module::Requirements (readonly)
Returns libraries that the module requires.
10 11 12 |
# File 'lib/ordinary/module.rb', line 10 def requirements @requirements ||= Requirements.new end |
Instance Method Details
#requires(*libraries) ⇒ Object
Add libraries to the requirements.
19 20 21 |
# File 'lib/ordinary/module.rb', line 19 def requires(*libraries) requirements.add(*libraries) end |
#unit(name, unit = nil) {|value, *args| ... } ⇒ Object
Define an unit for some normalizer.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ordinary/module.rb', line 62 def unit(name, unit = nil, &block) unit = unit.to_sym if unit.is_a?(String) unit = if unit.nil? and block.nil? unit_by_send(name) elsif unit.is_a?(Symbol) unit_by_send(unit) elsif unit.is_a?(Proc) create_unit(&unit) elsif block_given? create_unit(&block) else unit end unit.owned_by(self, name) unless unit.owned? define_method(name) { |*args| args.empty? ? unit : unit.with(*args) } module_function name end |