M
matt
With the usual deep_copy:
# Deep copy
class Object
def deep_copy
Marshal.load(Marshal.dump(self))
end
end
I get the following (irb 0.9(02/07/03))
irb(main):001:0> fmt = "%m-%d-%Y %H:%M"
=> "%m-%d-%Y %H:%M"
irb> original = Time.gm(2004, 04, 25, 22, 56)
=> Sun Apr 25 22:56:00 UTC 2004
irb> copy = original.deep_copy
=> Sun Apr 25 18:56:00 Eastern Daylight Time 2004
irb> [original, copy].map {|t| t.strftime(fmt)}
=> ["04-25-2004 22:56", "04-25-2004 18:56"]
irb> original.hour
=> 22
irb> copy.hour
=> 18
irb> original.hour <=> copy.hour
=> 1
irb> original <=> copy
=> 0
Ruh Roh!
# Deep copy
class Object
def deep_copy
Marshal.load(Marshal.dump(self))
end
end
I get the following (irb 0.9(02/07/03))
irb(main):001:0> fmt = "%m-%d-%Y %H:%M"
=> "%m-%d-%Y %H:%M"
irb> original = Time.gm(2004, 04, 25, 22, 56)
=> Sun Apr 25 22:56:00 UTC 2004
irb> copy = original.deep_copy
=> Sun Apr 25 18:56:00 Eastern Daylight Time 2004
irb> [original, copy].map {|t| t.strftime(fmt)}
=> ["04-25-2004 22:56", "04-25-2004 18:56"]
irb> original.hour
=> 22
irb> copy.hour
=> 18
irb> original.hour <=> copy.hour
=> 1
irb> original <=> copy
=> 0
Ruh Roh!