Class: Danica::VariablesHolder::VariablesBuilder
- Inherits:
-
Object
- Object
- Danica::VariablesHolder::VariablesBuilder
- Defined in:
- lib/danica/variables_holder/variables_builder.rb
Instance Attribute Summary collapse
-
#attr_names ⇒ Object
readonly
Returns the value of attribute attr_names.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(attr_names, instance) ⇒ VariablesBuilder
constructor
A new instance of VariablesBuilder.
Methods included from Wrapper
wrap_hash, wrap_numeric, wrap_value, #wrap_value
Methods included from DSL
build, #function, register, register_class, register_operator, register_wrapper
Constructor Details
#initialize(attr_names, instance) ⇒ VariablesBuilder
Returns a new instance of VariablesBuilder.
10 11 12 13 |
# File 'lib/danica/variables_holder/variables_builder.rb', line 10 def initialize(attr_names, instance) @instance = instance @attr_names = attr_names end |
Instance Attribute Details
#attr_names ⇒ Object (readonly)
Returns the value of attribute attr_names.
8 9 10 |
# File 'lib/danica/variables_holder/variables_builder.rb', line 8 def attr_names @attr_names end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
8 9 10 |
# File 'lib/danica/variables_holder/variables_builder.rb', line 8 def instance @instance end |
Instance Method Details
#build ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/danica/variables_holder/variables_builder.rb', line 15 def build names_hash = attr_names..symbolize_keys attr_names.map(&:to_sym).each do |name| add_setter(name) add_reader(name) instance.variables_hash[name] = wrap_value(name) end names_hash.each do |name, default| add_setter(name) add_reader(name) instance.variables_hash[name] = wrap_value(default) end end |