【发布时间】:2013-09-20 09:13:53
【问题描述】:
我已经使用强制来处理算术运算符:
class MyCustomClass
def coerce( other )
[MyCustomClass.new(other), self]
end
end
这意味着我可以做到:
42 + MyCustomClass.new
我想知道是否存在类似的机制,它可以让我进行比较(无需猴子修补 Fixnum):
42 > MyCustomClass.new
【问题讨论】:
标签: ruby comparison operators