Skip to content

Behavior of BooleanFactory on numeric types #10

@dhruvbansal

Description

@dhruvbansal

Run the following script

require 'gorillib/model'
class Foo
  include Gorillib::Model
  field   :boolsy, :boolean
end
[true, false, 'true', 'false', '0', '1', 0, 1,].each do |thing|
  puts [thing.inspect, Foo.receive(boolsy: thing).boolsy.to_s].join("\t")
end

Using latest Gorillib (0.5.0) I see

$ ruby bool_test.rb
true    true
false   false
"true"  true
"false" false
"0"     true
"1"     true
0       true
1       true

Shouldn't the behavior be to default to interpret 0 and "0" as false and 1 and "1" as true? Or is the belief that this pattern is "not common or reliable enough to encode in a library"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions