Class: Attrify::DSL::Variant
- Inherits:
-
Object
- Object
- Attrify::DSL::Variant
show all
- Defined in:
- lib/attrify/dsl/variant.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Variant.
8
9
10
|
# File 'lib/attrify/dsl/variant.rb', line 8
def initialize
@variants = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/attrify/dsl/variant.rb', line 21
def method_missing(name, *args, &block)
if block
@variants[name] = NestedVariant.new.build(&block)
elsif args.length == 1 && args[0].is_a?(Hash)
@variants[name] = args[0]
else
super
end
end
|
Instance Method Details
#build ⇒ Object
12
13
14
15
|
# File 'lib/attrify/dsl/variant.rb', line 12
def build(&)
instance_eval(&)
@variants
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
17
18
19
|
# File 'lib/attrify/dsl/variant.rb', line 17
def respond_to_missing?(name, include_private = false)
true
end
|