我希望能够比较Rails中的日期和时间,而无需总是调用to_time或to_date方法。所以我写了下面的代码:Rails中的日期/时间比较
class Date
def ==(other)
if other.kind_of?(Time)
self.to_time == other
else
super(other)
end
end
end
我知道有一个简单的方法来写,这样我可以使这个工作>,<,> =,< =和< =>。但我忘了如何:P任何想法?
这是我正在寻找的答案。谢谢! – gsmendoza 2009-02-13 07:13:16