Class: Attrify::DSL::Compound
- Inherits:
-
Object
- Object
- Attrify::DSL::Compound
- Defined in:
- lib/attrify/dsl/compound.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize ⇒ Compound
constructor
A new instance of Compound.
-
#slot(name, attributes) ⇒ Object
Explicit slot handling.
Constructor Details
#initialize ⇒ Compound
Returns a new instance of Compound.
8 9 10 |
# File 'lib/attrify/dsl/compound.rb', line 8 def initialize @compounds = {} end |
Instance Method Details
#build ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/attrify/dsl/compound.rb', line 12 def build(&) # Capture the result of the block execution result = instance_eval(&) # If the result is a hash and no slots were explicitly set, treat it as compound attributes if result.is_a?(Hash) && @compounds.empty? @compounds.merge!(result) end @compounds end |
#slot(name, attributes) ⇒ Object
Explicit slot handling
25 26 27 |
# File 'lib/attrify/dsl/compound.rb', line 25 def slot(name, attributes) @compounds[name] = attributes end |