1 28 package org.jruby; 29 30 import org.jruby.javasupport.Java; 31 import org.jruby.javasupport.JavaObject; 32 import org.jruby.runtime.Block; 33 import org.jruby.runtime.CallbackFactory; 34 import org.jruby.runtime.builtin.IRubyObject; 35 36 39 public class RubyJRuby { 40 public static RubyModule createJRuby(Ruby runtime) { 41 runtime.getModule("Kernel").callMethod(runtime.getCurrentContext(),"require", runtime.newString("java")); 42 RubyModule comparableModule = runtime.defineModule("JRuby"); 43 CallbackFactory callbackFactory = runtime.callbackFactory(RubyJRuby.class); 44 comparableModule.defineModuleFunction("parse", 45 callbackFactory.getSingletonMethod("parse", RubyKernel.IRUBY_OBJECT, RubyKernel.IRUBY_OBJECT)); 46 comparableModule.defineModuleFunction("runtime", 47 callbackFactory.getSingletonMethod("runtime")); 48 49 return comparableModule; 50 } 51 52 public static IRubyObject runtime(IRubyObject recv, Block unusedBlock) { 53 return Java.java_to_ruby(recv, JavaObject.wrap(recv.getRuntime(), recv.getRuntime()), Block.NULL_BLOCK); 54 } 55 56 public static IRubyObject parse(IRubyObject recv, IRubyObject arg1, IRubyObject arg2, Block unusedBlock) { 57 RubyString content = arg1.convertToString(); 58 RubyString filename = arg2.convertToString(); 59 return Java.java_to_ruby(recv, JavaObject.wrap(recv.getRuntime(), 60 recv.getRuntime().parse(content.toString(), filename.toString(), null)), Block.NULL_BLOCK); 61 } 62 } 63 | Popular Tags |