private Ruby createRuntime(String root, JsonObject options) {
Ruby runtime;
// if (Ruby.isGlobalRuntimeReady()) {
// runtime = Ruby.getGlobalRuntime();
// } else {
RubyInstanceConfig instanceConfig = new RubyInstanceConfig();
String jrubyHome = options.getString("jruby-home", "");
if (!jrubyHome.isEmpty()) {
instanceConfig.setJRubyHome(jrubyHome);
}
Object[] argv = options.getArray("argv", new JsonArray(new String[]{})).toArray();
instanceConfig.setArgv(Arrays.copyOf(argv, argv.length, String[].class));
// }
RubyArray globalLoadPaths = (RubyArray) Ruby.getGlobalRuntime().getLoadService().getLoadPath();
List<String> loadPaths = new ArrayList<>();
for (int i = 0; i < globalLoadPaths.size(); i++) {
IRubyObject entry = globalLoadPaths.eltInternal(i);
loadPaths.add(entry.asJavaString());
}
instanceConfig.setLoadPaths(loadPaths);
instanceConfig.setLoader(getClassLoader());
runtime = Ruby.newInstance(instanceConfig);
return runtime;
}