Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior of BooleanFactory on numeric types #10

Open
dhruvbansal opened this issue Aug 12, 2013 · 1 comment
Open

Behavior of BooleanFactory on numeric types #10

dhruvbansal opened this issue Aug 12, 2013 · 1 comment

Comments

@dhruvbansal
Copy link
Contributor

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"?

@mrflip
Copy link
Member

mrflip commented Aug 13, 2013

There's a :boolean_10 type that does exactly what you want.

On Aug 12, 2013, at 6:04 PM, Dhruv Bansal [email protected] wrote:

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"?


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants