These are chat archives for dry-rb/chat

Sep 2017
Rafael George
Sep 13 2017 00:21
why does 'Corceible' doesn't work with a default value? ->
if I instantiate this object without passing the volume it's just create the object setting that value to nil
is that because of Coercible ?
Sean Collins
Sep 13 2017 17:01
@cored I can’t reproduce that. When I try it, volume is set to 0.0 (as it should be)
Sean Collins
Sep 13 2017 17:07

in irb, using dry-types 0.11.1 (most recent release)

require 'dry-struct'
Types = Dry::Types.module
class TradingPartnerVariation < Dry::Struct
  constructor_type :schema
  attribute :volume, Types::Coercible::Float.default(0.0)

outputs => #<TradingPartnerVariation volume=0.0>

Rafael George
Sep 13 2017 17:23
@cllns thanks, so this was a object that is compose inside another object
for tihs to work properly I needed something like attribute Types::TradingPartnerVariation.default(
and that way I triggered the expected behavior
before wasn't instantiating a missing trading partner variation however as you mentioend this works with the coercible and default value
thanks for the reply