Class: T::Props::Private::ApplyFixedDefault

Inherits:
ApplyDefault show all
Defined in:
lib/types/props/private/apply_default.rb

Direct Known Subclasses

ApplyComplexDefault, ApplyPrimitiveDefault

Constant Summary

Constants inherited from ApplyDefault

T::Props::Private::ApplyDefault::NO_CLONE_TYPES

Constants included from Helpers

Helpers::Private

Instance Attribute Summary

Attributes inherited from ApplyDefault

#setter_proc

Instance Method Summary collapse

Methods inherited from ApplyDefault

#default, for

Methods included from Sig

#sig

Methods included from Helpers

#abstract!, #final!, #interface!, #mixes_in_class_methods, #requires_ancestor, #sealed!

Constructor Details

#initialize(default, accessor_key, setter_proc) ⇒ ApplyFixedDefault

Returns a new instance of ApplyFixedDefault.



71
72
73
74
75
76
77
78
79
80
# File 'lib/types/props/private/apply_default.rb', line 71

def initialize(default, accessor_key, setter_proc)
  # FIXME: Ideally we'd check here that the default is actually a valid
  # value for this field, but existing code relies on the fact that we don't.
  #
  # :(
  #
  # setter_proc.call(default)
  @default = T.let(default, BasicObject)
  super(accessor_key, setter_proc)
end

Instance Method Details

#set_default(instance) ⇒ Object



84
85
86
# File 'lib/types/props/private/apply_default.rb', line 84

def set_default(instance)
  instance.instance_variable_set(@accessor_key, default)
end