assets/src/org/ruboto/ScriptLoader.java in ruboto-0.10.0.rc.0 vs assets/src/org/ruboto/ScriptLoader.java in ruboto-0.10.0.rc.1

- old
+ new

@@ -33,24 +33,31 @@ final String script = rubyScript.getContents(); boolean scriptContainsClass = script.matches("(?s).*class " + component.getScriptInfo().getRubyClassName() + ".*"); boolean hasBackingJavaClass = component.getScriptInfo().getRubyClassName() .equals(component.getClass().getSimpleName()); - if (scriptContainsClass && !hasBackingJavaClass) { - System.out.println("Script defines methods on meta class"); - - // FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7 - if (JRubyAdapter.isJRubyPreOneSeven() || JRubyAdapter.isRubyOneEight()) { - JRubyAdapter.put("$java_instance", component); - rubyClass = JRubyAdapter.runScriptlet("class << $java_instance; self; end"); - } else if (JRubyAdapter.isJRubyOneSeven() && JRubyAdapter.isRubyOneNine()) { - JRubyAdapter.runScriptlet("Java::" + component.getClass().getName() + ".__persistent__ = true"); - rubyClass = JRubyAdapter.runRubyMethod(component, "singleton_class"); + if (scriptContainsClass) { + if (hasBackingJavaClass) { + if (rubyClass != null && !rubyClass.toString().startsWith("Java::")) { + System.out.println("Found Ruby class instead of Java class. Reloading."); + rubyClass = null; + } } else { - throw new RuntimeException("Unknown JRuby/Ruby version: " + JRubyAdapter.get("JRUBY_VERSION") + "/" + JRubyAdapter.get("RUBY_VERSION")); - } - // EMXIF + System.out.println("Script defines methods on meta class"); + // FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7 + if (JRubyAdapter.isJRubyPreOneSeven() || JRubyAdapter.isRubyOneEight()) { + JRubyAdapter.put("$java_instance", component); + rubyClass = JRubyAdapter.runScriptlet("class << $java_instance; self; end"); + } else if (JRubyAdapter.isJRubyOneSeven() && JRubyAdapter.isRubyOneNine()) { + JRubyAdapter.runScriptlet("Java::" + component.getClass().getName() + ".__persistent__ = true"); + rubyClass = JRubyAdapter.runRubyMethod(component, "singleton_class"); + } else { + throw new RuntimeException("Unknown JRuby/Ruby version: " + JRubyAdapter.get("JRUBY_VERSION") + "/" + JRubyAdapter.get("RUBY_VERSION")); + } + // EMXIF + + } } if (rubyClass == null || !hasBackingJavaClass) { System.out.println("Loading script: " + component.getScriptInfo().getScriptName()); if (scriptContainsClass) { System.out.println("Script contains class definition");