We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Learn more about funding links in repositories.
Report abuse
to_unsafe
1 parent 68a7ce8 commit 56b8eddCopy full SHA for 56b8edd
spec/std/bool_spec.cr
@@ -31,6 +31,11 @@ describe "Bool" do
31
it { true.hash.should_not eq(false.hash) }
32
end
33
34
+ describe "to_unsafe" do
35
+ it { true.to_unsafe.should eq(1) }
36
+ it { false.to_unsafe.should eq(0) }
37
+ end
38
+
39
describe "to_s" do
40
it { true.to_s.should eq("true") }
41
it { false.to_s.should eq("false") }
src/bool.cr
@@ -46,6 +46,11 @@ struct Bool
46
hasher.bool(self)
47
48
49
+ # Returns `1` for `true` and `0` for `false`.
50
+ def to_unsafe
51
+ self ? 1 : 0
52
53
54
# Returns `"true"` for `true` and `"false"` for `false`.
55
def to_s
56
self ? "true" : "false"
0 commit comments