Module: MiniTools::ItemFactory::ClassMethods
- Defined in:
- lib/mini_tools/item_factory.rb
Instance Attribute Summary collapse
-
#default_klass ⇒ Object
readonly
Returns the value of attribute default_klass.
Instance Method Summary collapse
-
#build(value, *args) ⇒ Object
Builds the appropriate item based on ‘value`.
-
#default(klass) ⇒ Object
Sets the default class if there is no match in the map.
-
#map(values) ⇒ Object
Defines the map of values to class types.
Instance Attribute Details
#default_klass ⇒ Object (readonly)
Returns the value of attribute default_klass.
36 37 38 |
# File 'lib/mini_tools/item_factory.rb', line 36 def default_klass @default_klass end |
Instance Method Details
#build(value, *args) ⇒ Object
Builds the appropriate item based on ‘value`. Any additional args are passed on to the item’s initializer
40 41 42 |
# File 'lib/mini_tools/item_factory.rb', line 40 def build value, *args klass_for(value).new(*args) end |
#default(klass) ⇒ Object
Sets the default class if there is no match in the map
50 51 52 |
# File 'lib/mini_tools/item_factory.rb', line 50 def default klass @default_klass = klass end |
#map(values) ⇒ Object
Defines the map of values to class types
45 46 47 |
# File 'lib/mini_tools/item_factory.rb', line 45 def map values @klass_map = values end |