I am upgrading the ruby version from ruby 1.8.7 to ruby 1.9.2 in my exiting Ruby on rails application which has extensive use of Time related calculations. But after switching to ruby 1.9.2 -p290 its not working. I guess the issue is with
在我现有的ruby on rails应用程序中,我正在将ruby版本从ruby 1.8.7升级到ruby 1.9.2,该应用程序广泛地使用了与时间相关的计算。但是在切换到ruby 1.9.2 -p290之后,它就不起作用了。我想问题在于
$ rvm use 1.8.7
ruby-1.8.7-p334 :001 > Time.now
=> Thu May 12 12:42:35 +0200 2011
$ rvm use 1.9.2
ruby-1.9.2-p180 :001 > Time.now
=> 2011-05-12 12:42:44 +0200
Can some please tell me how to solve this kind of issue or How can change or override default ruby 1.9.2 format back to the old one or how to solve this time related changes in the newer version of ruby.
请告诉我如何解决这类问题,或者如何更改或覆盖默认的ruby 1.9.2格式回到旧的版本,或者如何解决新版本ruby中这次相关的更改。
Thanks
谢谢
1 个解决方案
#1
2
you can use
您可以使用
Time.now.asctime
in 1.9
在1.9
EDIT 1:
编辑1:
well, depends on how you're going to use it. This should probably work for you:
这取决于你如何使用它。这可能对你有用:
irb(main):001:0> class Time
irb(main):002:1> class << self
irb(main):003:2> alias :orig_now :now
irb(main):004:2>
irb(main):005:2* def now
irb(main):006:3> orig_now.asctime
irb(main):007:3> end
irb(main):008:2> end
irb(main):009:1> end
=> nil
irb(main):010:0> Time.now
=> "Thu Jul 28 12:29:08 2011" # STRING
irb(main):011:0>
EDIT 2:
编辑2:
Ok, I got your question somewhat wrong. The above patch will cause Time.now to return the string (not the Time object).
好吧,我把你的问题说错了。以上补丁将导致时间。现在返回字符串(不是时间对象)。
If you just want to see Time object to be represented different you could apply this:
如果你只是想看到时间对象被表示为不同的,你可以应用这个:
irb(main):011:0> class Time
irb(main):012:1>
irb(main):013:1* def inspect
irb(main):014:2> self.asctime
irb(main):015:2> end
irb(main):016:1> end
=> nil
irb(main):017:0> Time.now
=> Thu Jul 28 13:41:16 2011 # TIME
#1
2
you can use
您可以使用
Time.now.asctime
in 1.9
在1.9
EDIT 1:
编辑1:
well, depends on how you're going to use it. This should probably work for you:
这取决于你如何使用它。这可能对你有用:
irb(main):001:0> class Time
irb(main):002:1> class << self
irb(main):003:2> alias :orig_now :now
irb(main):004:2>
irb(main):005:2* def now
irb(main):006:3> orig_now.asctime
irb(main):007:3> end
irb(main):008:2> end
irb(main):009:1> end
=> nil
irb(main):010:0> Time.now
=> "Thu Jul 28 12:29:08 2011" # STRING
irb(main):011:0>
EDIT 2:
编辑2:
Ok, I got your question somewhat wrong. The above patch will cause Time.now to return the string (not the Time object).
好吧,我把你的问题说错了。以上补丁将导致时间。现在返回字符串(不是时间对象)。
If you just want to see Time object to be represented different you could apply this:
如果你只是想看到时间对象被表示为不同的,你可以应用这个:
irb(main):011:0> class Time
irb(main):012:1>
irb(main):013:1* def inspect
irb(main):014:2> self.asctime
irb(main):015:2> end
irb(main):016:1> end
=> nil
irb(main):017:0> Time.now
=> Thu Jul 28 13:41:16 2011 # TIME