Class: T::Props::Private::ApplyDefaultFactory
- Inherits:
-
ApplyDefault
- Object
- ApplyDefault
- T::Props::Private::ApplyDefaultFactory
- Defined in:
- lib/types/props/private/apply_default.rb
Constant Summary
Constants inherited from ApplyDefault
T::Props::Private::ApplyDefault::NO_CLONE_TYPES
Constants included from Helpers
Instance Attribute Summary
Attributes inherited from ApplyDefault
Instance Method Summary collapse
- #default ⇒ Object
-
#initialize(cls, factory, accessor_key, setter_proc) ⇒ ApplyDefaultFactory
constructor
A new instance of ApplyDefaultFactory.
- #set_default(instance) ⇒ Object
Methods inherited from ApplyDefault
Methods included from Sig
Methods included from Helpers
#abstract!, #final!, #interface!, #mixes_in_class_methods, #requires_ancestor, #sealed!
Constructor Details
#initialize(cls, factory, accessor_key, setter_proc) ⇒ ApplyDefaultFactory
Returns a new instance of ApplyDefaultFactory.
149 150 151 152 153 |
# File 'lib/types/props/private/apply_default.rb', line 149 def initialize(cls, factory, accessor_key, setter_proc) @class = T.let(cls, Module) @factory = T.let(factory, T.any(Proc, Method)) super(accessor_key, setter_proc) end |
Instance Method Details
#default ⇒ Object
165 166 167 |
# File 'lib/types/props/private/apply_default.rb', line 165 def default @class.class_exec(&@factory) end |
#set_default(instance) ⇒ Object
157 158 159 160 161 |
# File 'lib/types/props/private/apply_default.rb', line 157 def set_default(instance) # Use the actual setter to validate the factory returns a legitimate # value every time instance.instance_exec(default, &@setter_proc) end |