Closed ajvondrak closed 9 years ago
Using virtus-1.0.2:
[1] pry(main)> require 'virtus' => true [2] pry(main)> class Model [2] pry(main)* include Virtus.model(strict: true) [2] pry(main)* attribute :boolean, Boolean [2] pry(main)* attribute :booleans, Array[Boolean] [2] pry(main)* end => Model [3] pry(main)> Model.new(boolean: 0, booleans: [0, 1, 'yes', 'no', 'hi', 'bye', nil]) => #<Model:0x007fdd2cbd4438 @boolean=false, @booleans=[false, true, true, false, "hi", "bye", nil]> [4] pry(main)> Model.new(boolean: 'hi', booleans: [0, 1, 'yes', 'no', 'hi', 'bye', nil]) Virtus::CoercionError: Failed to coerce "hi" into BasicObject from ~/.rvm/gems/ruby-2.0.0-p353/gems/virtus-1.0.2/lib/virtus/attribute/strict.rb:19:in `coerce'
Notice that booleans silently has the non-coercible values, while boolean will raise the strict error.
booleans
boolean
Using virtus-1.0.2:
Notice that
booleans
silently has the non-coercible values, whileboolean
will raise the strict error.