Module: AttrTypecastable::InitializeHook
- Defined in:
- lib/attr_typecastable/initialize_hook.rb
Instance Method Summary collapse
Instance Method Details
#initialize ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/attr_typecastable/initialize_hook.rb', line 3 def initialize(*) super self.class.typed_attr_reflections.select {|_, r| r.has_default?}.each do |attr, reflection| current = send("#{attr}") next unless current.nil? default = reflection.default v = default.respond_to?(:call) ? default.call(self, attr) : default send("#{attr}=", v) end end |