These are chat archives for dry-rb/chat

13th
Sep 2017
Rafael George
@cored
Sep 13 2017 00:21
why does 'Corceible' doesn't work with a default value? -> https://gist.github.com/cored/7519467381731d4d1936bd9290b73160
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
@cllns
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
@cllns
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)
end
TradingPartnerVariation.new

outputs => #<TradingPartnerVariation volume=0.0>

Rafael George
@cored
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(TradingPartnerVariation.new)
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