File tree 3 files changed +22
-2
lines changed
3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 1
1
name : csuuid
2
- version : 0.2.3
2
+ version : 0.2.4
3
3
4
4
authors :
5
5
Original file line number Diff line number Diff line change @@ -91,4 +91,12 @@ describe CSUUID do
91
91
uuids = CSUUID .generate(10000 )
92
92
uuids.uniq.size.should eq uuids.size
93
93
end
94
+
95
+ it " can compare CSUUIDs via <=>" do
96
+ uuid1 = CSUUID .new
97
+ uuid2 = CSUUID .new
98
+ (uuid1 <=> uuid2).should eq -1
99
+ (uuid2 <=> uuid1).should eq 1
100
+ (uuid1 <=> uuid1).should eq 0
101
+ end
94
102
end
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ require "crystal/spin_lock"
40
40
# ```
41
41
#
42
42
struct CSUUID
43
- VERSION = " 0.2.3 "
43
+ VERSION = " 0.2.4 "
44
44
45
45
@@mutex = Crystal ::SpinLock .new
46
46
# @@mutex = Mutex.new(protection: Mutex::Protection::Reentrant)
@@ -168,4 +168,16 @@ struct CSUUID
168
168
hs = @bytes .hexstring
169
169
io << " #{ hs[0 ..7] } -#{ hs[8 ..11] } -#{ hs[12 ..15] } -#{ hs[16 ..19] } -#{ hs[20 ..31] } "
170
170
end
171
+
172
+ def <=> (val )
173
+ s, ns = seconds_and_nanoseconds
174
+ s_val, ns_val = val.seconds_and_nanoseconds
175
+ r = s <=> s_val
176
+ return r unless r == 0
177
+
178
+ r = ns <=> ns_val
179
+ return r unless r == 0
180
+
181
+ to_s <=> val.to_s
182
+ end
171
183
end
You can’t perform that action at this time.
0 commit comments