Package org.jruby

Examples of org.jruby.IRuby


public class ScriptRunner extends TestCase{
    private static final String DATA = "src-ruby-tests/data/";

    public void test() {
        IRuby runtime = org.jruby.Ruby.getDefaultInstance();
        try {
            File f = new File(DATA + "snippets1.rb");
            runtime.loadFile(f, false);
            f = new File(DATA + "snippets2.rb");
            runtime.loadFile(f, false);
            IRubyObject rubyObject = runtime.evalScript("init");
            Assert.assertNotNull(rubyObject);
            rubyObject = runtime.evalScript("init");
            Assert.assertNotNull(rubyObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here


       
        args = rec.processForLearningMode(args);

        String filePath = args[0];

        IRuby runtime = JavaEmbedUtils.initialize(Collections.singletonList("."));
        IRubyObject conn = JavaEmbedUtils.javaToRuby(runtime, new DefaultStreamConnection());

        try {
          // deprecated
            runtime.getGlobalVariables().set(GlobalVariable.variableName("ssh"), conn);
           
            runtime.getGlobalVariables().set(GlobalVariable.variableName("conn"), conn);
            runtime.getGlobalVariables().set(GlobalVariable.variableName("args"), JavaEmbedUtils.javaToRuby(runtime, args));
            runtime.loadFile(new File(filePath), false);
        } catch (JumpException je) {
            if (je.getJumpType() == JumpException.JumpType.RaiseJump) {
                RubyException raisedException = ((RaiseException)je).getException();

                if (raisedException.isKindOf(runtime.getClass("SystemExit"))) {
                    RubyFixnum status = (RubyFixnum)raisedException.getInstanceVariable("status");

                    if (status != null) {
                        System.exit(RubyNumeric.fix2int(status));
                    }
                } else {
                    runtime.printError(raisedException);
                    System.exit(1);
                }
            } else if (je.getJumpType() == JumpException.JumpType.ThrowJump) {
                runtime.printError((RubyException)je.getTertiaryData());
                System.exit(1);
            } else {
                //throw je;
            }
        } catch(MainExitException e) {
View Full Code Here

TOP

Related Classes of org.jruby.IRuby

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.