gpt4 book ai didi

Ruby 与 JRuby : Time. 新

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

我有一个可以运行的网络应用程序,主要用于 MRI Ruby 和 JRuby。但是……

当我使用 MRI 时,我可以做到这一点。

> rails console
irb(main):001:0> a=Time.new(1,1,1,1,1)
=> 0001-01-01 01:01:00 -0500

即它为指定时间创建一个新的 Time 对象。

当我切换到 JRuby 时,我会这样做

> rails console
irb(main):001:0> a=Time.new(1,1,1,1,1)
ArgumentError: wrong number of arguments (5 for 0)
from (irb):2: in `evaluate`
from org/jruby/RubyKernel.java:1088 in `eval`
from /home/user/.rbenv/versions/jruby-1.6.4/lib/ruby/1.8/irb.rb:158 in `eval_input`
from /home/user/.rbenv/versions/jruby-1.6.4/lib/ruby/1.8/
....

如何在 JRuby 中创建一个时间对象,其中包含我控制的年、月、日、小时和分钟?如果是这样,它也可以与 MRI Ruby 一起使用吗?

我不知道这是否相关,但是

irb(main):002:0> RUBY_VERSION
"1.8.7"

我的问题可能是因为我处于 1.8.7 模式吗?如果是这样,我如何将我的 rbenv/jruby-1.6.4 安装切换为像 RUBY_VERSION=1.9.2 一样?

最佳答案

是的,跟RUBY_VERSION有关
您需要 JRUBY 处于 1.9 模式。
您可以通过 JRUBY_OPTS 进行设置

试试这个:

export JRUBY_OPTS=--1.9

或这个(在 Windows 上):

set JRUBY_OPTS=--1.9

示例 session (Windows):

> set JRUBY_OPTS=--1.9
> jirb
irb(main):001:0> a=Time.new(1,1,1,1,1)
=> 0001-01-01 01:01:00 +0918

关于Ruby 与 JRuby : Time. 新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7830404/

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