1

I have a web app which works, for the most part with MRI Ruby and JRuby. But...

When I am using MRI, I can do this.

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

i.e. It creates a new Time object for the specified time.

When I switch to JRuby I do this

> 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/
....

How can I create a Time object in JRuby with a year, month, day, hour, and minutes which I control? If so, can this work with MRI Ruby as well?

I don't know if this is related, but

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

Could my problem be because I'm in 1.8.7 mode? If so, how do I switch my rbenv/jruby-1.6.4 installation to act like RUBY_VERSION=1.9.2 ?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Jay Godse
  • 15,163
  • 16
  • 84
  • 131

1 Answers1

7

Yes, it is related to the RUBY_VERSION
You need JRUBY to be in 1.9 mode.
You can set this through JRUBY_OPTS

Try this:

export JRUBY_OPTS=--1.9

or this (on Windows):

set JRUBY_OPTS=--1.9

Example 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
Kevin Radcliffe
  • 991
  • 1
  • 11
  • 21