Hi all.
I am experiencing a curious issue.
Some library was calling ARGV.shift, and this failed because the shift
method was missing from whatever object was in ARGV. I isolated it to
a simpler test case:
ScriptEngine engine = new
ScriptEngineManager().getEngineByExtension(“rb”);
ScriptContext context = engine.getContext();
context.setAttribute(ScriptEngine.ARGV, new String[] { “a”, “b” },
ScriptContext.ENGINE_SCOPE);
Object result = engine.eval(“ARGV.shift + ARGV.shift”, context);
assertEquals(“Expected the sum of the strings”, “ab”, result);
This gives:
org.jruby.embed.EvalFailedException: undefined method `shift’ for
#<#Class:01x156a9424:0x7adafa2c>
If I try using an ArrayList instead, I get the same result.
Is this supposed to work? The library in question is ‘optparse’, part
of the Ruby standard library, so the bug must be either in ‘optparse’
(“ARGV is mutable so you shouldn’t call shift on it”) or in JRuby
(“ARGV should be mutable so shift should work like it would work for
any other array”.) If I naively just start up irb and type in
ARGV.shift, it does successfully return nil.
In all other respects, the object works as expected, so I can just add
a “.to_a” in to make everything work, which will be my workaround for
now.
The behaviour is identical on 1.5.6 and 1.6.0 RC1.
TX