-
Notifications
You must be signed in to change notification settings - Fork 0
Well_ordered
x768 edited this page Sep 23, 2017
·
1 revision
Well-ordered is an ability of class.
let a = 1 // Int class has Well-ordered ability
let b = 10
puts a > b // false
puts a < b // true
let arr = [1, 3, 2]
puts a.sort() // [1, 2, 3]
for i in a..b {
puts i // 1 2 3 ... 9
}
Must implement following methods.
op_cmp(r):Int
Returns negative integer if left object is less than right. Returns positive integer if left object is greater than right. Otherwise returns 0
puts 1.op_cmp(3) // -1
puts 1 < 3 // same as 1.op_cmp(3) < 0
puts 1 >= 3 // same as 1.op_cmp(3) >= 0