def define_attr_writer(name, type)
      define_method("#{name}=") do |value|
        unless value.kind_of?(type)
          value = coerce(value, to: type)
          unless value.kind_of?(type)
            raise TypeError, "Attribute `#{name}` only accepts `#{type}` but got `#{value}`:`#{value.class}` instead"
          end
        end
        instance_variable_set("@#{name}", value)
      end
    end
def define_attr_writer(name, type)
      define_method("#{name}=") do |value|
        unless value.kind_of?(type)
          value = coerce(value, to: type)
          unless value.kind_of?(type)
            raise TypeError, "Attribute `#{name}` only accepts `#{type}` but got `#{value}`:`#{value.class}` instead"
          end
        end
        instance_variable_set("@#{name}", value)
      end
    end
Define attr_writer method for the new attribute
   with the added feature of validations and coercions.

 @param [Symbol] name the attribute name
 @param [Class] type the class type

 @raise [TypeError] if unable to coerce the value

 @private