gpt4 book ai didi

ruby-on-rails - IRB 控制台中的未定义方法 `change' DateTime

转载 作者:太空宇宙 更新时间:2023-11-03 17:05:33 26 4
gpt4 key购买 nike

更改(:小时 => 1)在 Rails 控制台中正常工作

irb(main):004:0> dt = DateTime.now
=> Mon, 10 Dec 2012 15:52:01 -0800
irb(main):005:0> _.change(:hour => 1)
=> Mon, 10 Dec 2012 01:00:00 -0800
irb(main):006:0>
irb(main):007:0> dt.class
=> DateTime
irb(main):008:0>

但是在 irb 中抛出“undefined method `change'”

irb(main):008:0> require 'active_record'
=> true
irb(main):009:0> dt = DateTime.now
=> #<DateTime: 2012-12-10T15:55:14-08:00 (10611097185737/4320000,-1/3,2299161)>
irb(main):010:0> dt.class
=> DateTime
irb(main):011:0> dt.change(:hour => 1)
NoMethodError: undefined method `change' for #<DateTime:0x53e20a9a>
from (irb):11:in `evaluate'
from org/jruby/RubyKernel.java:1070:in `eval'
from org/jruby/RubyKernel.java:1395:in `loop'
from org/jruby/RubyKernel.java:1178:in `catch'
from org/jruby/RubyKernel.java:1178:in `catch'
from C:\PF\jruby-1.7.0.preview2\bin\irb:13:in `(root)'
irb(main):012:0>

有什么建议可以让它发挥作用吗?

提前致谢。

最佳答案

要获得与日期时间相关的功能,只需require 'active_support/time'

关于ruby-on-rails - IRB 控制台中的未定义方法 `change' DateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13818294/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com