【发布时间】:2012-02-04 11:46:03
【问题描述】:
我需要使用 Time 对象作为 int (TimeObject.to_i) 然后我需要将一个 int 转换回一个时间,以与原始时间进行比较。 简短的例子
t1 = Time.now
t2 = Time.at(t1.to_i)
puts t1 == t2 # Says False
puts t1.eql?(t2) # Says False
为什么这说它是假的? 当我打印两个时间对象时显示相同的东西 D:
puts t1 #shows : 2012-01-06 16:01:53 -0300
puts t2 #shows : 2012-01-06 16:01:53 -0300
puts t1.to_a.to_s #shows : [ 53, 1, 16, 6, 1, 2012, 5, 6, true, "CLST"]
puts t2.to_a.to_s #shows : [ 53, 1, 16, 6, 1, 2012, 5, 6, true, "CLST"]
它们是相同的东西 D: 但是当试图与 == 或 eql 进行比较时?说他们不同 (对不起我的英语不好)
【问题讨论】: