rubyjruby

Is there a way to get the JRuby script in the StackTraceElements in JRuby StackTraces


I am using JRuby, but I am often calling scripts from other scripts, which means that when I have StackTraces from the Java caller, not all the StackTraceElements are coming from the initial calling class.

For example, if I have the following code in Ruby:

public
  def compute()
    retur 10
  end

I have the following StackTraceElement:

I would like to get somewhere the name of my script, is it possible to get it in JRuby?

I am creating the script by:

    RubyRuntimeAdapter adapter = JavaEmbedUtils.newRuntimeAdapter();
    IRubyObject io = adapter.eval(runtime, <scriptContent>);

Solution

  • I understood how to do it. Rather than:

    IRubyObject io = adapter.eval(runtime, <scriptContent>);
    

    I have to do:

    JavaEmbedUtils.EvalUnit evalUnit = adapter.parse(runtime, <scriptContent>, <file name>, 1);
    IRubyObject io = evalUnit.run();