覆盖<在Pharo

Bou*_*uet 2 overriding smalltalk pharo

我试图覆盖pharo中的'<'运算符,因为我想要一个已实现的类(TimeCal)的SortedCollection.

TimeCal具有以下变量:年月日时分钟.

我的想法是将所有变量转换为分钟,然后将它们与<运算符接收的比较进行比较.但是,我确实收到了错误

"BlockClosure(Object)>> doesNotUnderstand:#>"

这是我的代码:

< comparand
| thisInMins comparandInMins |
thisInMins := [(year * 525600) + (month * 43829) + (day * 1440) + (hour * 60) + minute].
comparandInMins := [(comparand year * 525600) + (comparand month * 43829) + (comparand day * 1440) + (comparand hour * 60) + comparand minute].

(thisInMins > comparandInMins)
ifTrue: [true] ifFalse: [false]
Run Code Online (Sandbox Code Playgroud)

我用来测试它的代码:

time1 := TimeCal new. 
time1 hour: 12.
time1 day: 12.
time1 month: 11.
time2 := TimeCal new. 
time2 hour: 12.
time2 day: 12.
time2 month: 8.
testing := time1 < time2.
Run Code Online (Sandbox Code Playgroud)

我不确定我所做的是否正确.我找不到任何关于如何做的正确指南.

Lea*_*lia 5

那这个呢

< other
    year = other year ifFalse: [^year < other year].
    month = other month ifFalse: [^month < other month].
    day = other day ifFalse: [^day < other day].
    hour = other hour ifFalse: [^hour < other hour].
    ^minute < other minute
Run Code Online (Sandbox Code Playgroud)