Module: Gamera::Builder::Dsl
- Included in:
- Gamera::Builder
- Defined in:
- lib/gamera/builder.rb
Overview
Module to extend the Builder DSL
Instance Method Summary collapse
-
#default_for(option_name, val = nil, &gen) ⇒ Object
Sets the default value of an option.
Instance Method Details
#default_for(option_name, val = nil, &gen) ⇒ Object
Sets the default value of an option
Yields self to block (gen
) if a block is provided. Return value will be the default value.
149 150 151 152 153 154 155 156 157 |
# File 'lib/gamera/builder.rb', line 149 def default_for(option_name, val = nil, &gen) gen ||= ->(_) { val } prepend(Module.new do define_method :"#{option_name}_coercion" do |v| super v.nil? ? gen.call(self) : v end end) end |