当前位置: 首页>>代码示例>>Java>>正文


Java Ruby类代码示例

本文整理汇总了Java中org.jruby.Ruby的典型用法代码示例。如果您正苦于以下问题:Java Ruby类的具体用法?Java Ruby怎么用?Java Ruby使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Ruby类属于org.jruby包,在下文中一共展示了Ruby类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: map2hash

import org.jruby.Ruby; //导入依赖的package包/类
@SuppressWarnings("unchecked") private static RubyHash map2hash(Ruby ruby, Map<String, Object> ourCaps) {
    RubyHash hash = new RubyHash(ruby);
    Set<String> keySet = ourCaps.keySet();
    for (String key : keySet) {
        RubySymbol keySym = RubySymbol.newSymbol(ruby, key);
        Object v = ourCaps.get(key);
        if (v instanceof String) {
            hash.put(keySym, RubyString.newString(ruby, (String) v));
        } else if(v instanceof Boolean) {
            hash.put(keySym, RubyBoolean.newBoolean(ruby, (boolean) v));
        } else if (v instanceof List) {
            hash.put(keySym, map2list(ruby, (List<?>) v));
        } else {
            hash.put(keySym, map2hash(ruby, (Map<String, Object>) v));
        }
    }
    return hash;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:MarathonRuby.java

示例2: map2list

import org.jruby.Ruby; //导入依赖的package包/类
@SuppressWarnings("unchecked") private static RubyArray map2list(Ruby ruby, List<?> list) {
    RubyArray array = new RubyArray(ruby, list.size());
    int index = 0;
    for (Object v : list) {
        if (v instanceof String) {
            array.set(index++, RubyString.newString(ruby, (String) v));
        } else if(v instanceof Boolean) {
            array.set(index++, RubyBoolean.newBoolean(ruby, (boolean) v));
        } else if (v instanceof List) {
            array.set(index++, map2list(ruby, (List<?>) v));
        } else {
            array.set(index++, map2hash(ruby, (Map<String, Object>) v));
        }
    }
    return array;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:17,代码来源:MarathonRuby.java

示例3: getInitRuby

import org.jruby.Ruby; //导入依赖的package包/类
protected Callable<Ruby> getInitRuby(final Writer out, final Writer err) {
    return new Callable<Ruby>() {
        @Override public Ruby call() throws Exception {
            RubyInstanceConfig config = new RubyInstanceConfig();
            config.setCompileMode(CompileMode.OFF);
            List<String> loadPaths = new ArrayList<String>();
            setModule(loadPaths);
            String appRubyPath = System.getProperty(PROP_APPLICATION_RUBYPATH);
            if (appRubyPath != null) {
                StringTokenizer tok = new StringTokenizer(appRubyPath, ";");
                while (tok.hasMoreTokens()) {
                    loadPaths.add(tok.nextToken().replace('/', File.separatorChar));
                }
            }
            config.setOutput(new PrintStream(new WriterOutputStream(out)));
            config.setError(new PrintStream(new WriterOutputStream(err)));
            Ruby interpreter = JavaEmbedUtils.initialize(loadPaths, config);
            interpreter.evalScriptlet("require 'selenium/webdriver'");
            interpreter.evalScriptlet("require 'marathon/results'");
            interpreter.evalScriptlet("require 'marathon/playback-" + framework + "'");
            return interpreter;
        }
    };
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:25,代码来源:RubyScript.java

示例4: checkForWindowNameAndComments

import org.jruby.Ruby; //导入依赖的package包/类
public void checkForWindowNameAndComments() throws Exception {
    ModuleList moduleList = new ModuleList(Ruby.newInstance(), "authentication");
    Module top = moduleList.getTop();
    List<Module> modules = top.getChildren();
    assertEquals(1, modules.size());
    Module login = modules.get(0);
    assertEquals("login", login.getName());
    List<Function> functions = login.getFunctions();
    assertEquals(2, functions.size());
    Function loginFunction = functions.get(0);
    String lineSepearator = System.getProperty("line.separator");
    assertEquals(
            convert2code(new String[] { "=begin", "This is an example with with_window call and comments", "=end" }).trim(),
            loginFunction.getDocumentation().trim().replaceAll("\n", lineSepearator));
    assertEquals("Login", loginFunction.getWindow());
    Function loginFunction2 = functions.get(1);
    assertEquals("", loginFunction2.getDocumentation());
    assertNull(loginFunction2.getWindow());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:20,代码来源:ModuleListTest.java

示例5: checkForListArgs

import org.jruby.Ruby; //导入依赖的package包/类
public void checkForListArgs() throws Exception {
    ModuleList moduleList = new ModuleList(Ruby.newInstance(), "selection");
    Module top = moduleList.getTop();
    List<Module> modules = top.getChildren();
    assertEquals(1, modules.size());
    Module arrays = modules.get(0);
    assertEquals("arrays", arrays.getName());
    List<Function> functions = arrays.getFunctions();
    assertEquals(3, functions.size());
    Function selectOneFunction = functions.get(0);
    assertEquals("select_one", selectOneFunction.getName());
    List<Argument> arguments = selectOneFunction.getArguments();
    assertEquals(2, arguments.size());
    Argument arg = arguments.get(0);
    assertEquals("integers", arg.getName());
    assertNull(arg.getDefault());
    assertNotNull(arg.getDefaultList());
    arg = arguments.get(1);
    assertEquals("strings", arg.getName());
    assertNull(arg.getDefault(), arg.getDefault());
    assertNotNull(arg.getDefaultList());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:23,代码来源:ModuleListTest.java

示例6: resultsCapturesJavaError

import org.jruby.Ruby; //导入依赖的package包/类
@Test(enabled = false) public void resultsCapturesJavaError() throws Exception {
    RubyScript script = new RubyScript(out, err, converToCode(SCRIPT_CONTENTS_ERROR_FROM_JAVA),
            new File(System.getProperty(Constants.PROP_PROJECT_DIR), "dummyfile.rb").getAbsolutePath(), false, null,
            Constants.FRAMEWORK_SWING);
    script.setDriverURL("");
    Ruby interpreter = script.getInterpreter();
    assertTrue("Collector not defined", interpreter.isClassDefined("Collector"));
    RubyClass collectorClass = interpreter.getClass("Collector");
    IRubyObject presult = JavaEmbedUtils.javaToRuby(interpreter, result);
    IRubyObject collector = collectorClass.newInstance(interpreter.getCurrentContext(), new IRubyObject[0], new Block(null));
    IRubyObject rubyObject = interpreter.evalScriptlet("proc { my_function }");
    try {
        collector.callMethod(interpreter.getCurrentContext(), "callprotected", new IRubyObject[] { rubyObject, presult });
    } catch (Throwable t) {

    }
    assertEquals(1, result.failureCount());
    Failure[] failures = result.failures();
    assertTrue("Should end with TestRubyScript.java. but has " + failures[0].getTraceback()[0].fileName,
            failures[0].getTraceback()[0].fileName.endsWith("TestRubyScript.java"));
    assertEquals("throwError", failures[0].getTraceback()[0].functionName);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:23,代码来源:RubyScriptTest.java

示例7: createJRubyObject

import org.jruby.Ruby; //导入依赖的package包/类
/**
 * Create a new JRuby-scripted object from the given script source.
 * @param scriptSource the script source text
 * @param interfaces the interfaces that the scripted Java object is to implement
 * @param classLoader the {@link ClassLoader} to create the script proxy with
 * @return the scripted Java object
 * @throws JumpException in case of JRuby parsing failure
 */
public static Object createJRubyObject(String scriptSource, Class<?>[] interfaces, ClassLoader classLoader) {
	Ruby ruby = initializeRuntime();

	Node scriptRootNode = ruby.parseEval(scriptSource, "", null, 0);
       IRubyObject rubyObject = ruby.runNormally(scriptRootNode);

	if (rubyObject instanceof RubyNil) {
		String className = findClassName(scriptRootNode);
		rubyObject = ruby.evalScriptlet("\n" + className + ".new");
	}
	// still null?
	if (rubyObject instanceof RubyNil) {
		throw new IllegalStateException("Compilation of JRuby script returned RubyNil: " + rubyObject);
	}

	return Proxy.newProxyInstance(classLoader, interfaces, new RubyObjectInvocationHandler(rubyObject, ruby));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:JRubyScriptUtils.java

示例8: run

import org.jruby.Ruby; //导入依赖的package包/类
private void run(final Ruby runtime) {
    Thread t2 = new Thread() {
        public void run() {
            try {
                InputStream is = getClass().getResourceAsStream("/console_irb.rb");

                ByteArrayOutputStream ba = new ByteArrayOutputStream();
                int r;
                while ((r = is.read()) >= 0)
                    ba.write(r);
                is.close();

                //runtime
                //	.evalScriptlet("require 'irb'\n require 'irb/completion'\n IRB.start(__FILE__)\n");
                runtime.evalScriptlet(new String(ba.toByteArray()));
                //run();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    t2.start();
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:24,代码来源:RubyConsole.java

示例9: hookIntoRuntime

import org.jruby.Ruby; //导入依赖的package包/类
/**
 * Hooks this <code>TextAreaReadline</code> instance into the runtime,
 * redefining the <code>Readline</code> module so that it uses this object.
 * This method does not redefine the standard input-output streams. If you
 * need that, use {@link #hookIntoRuntimeWithStreams(Ruby)}.
 *
 * @param runtime The runtime.
 * @see #hookIntoRuntimeWithStreams(Ruby)
 */
public void hookIntoRuntime(final Ruby runtime) {
    this.runtime = runtime;
    /* Hack in to replace usual readline with this */
    runtime.getLoadService().require("readline");
    RubyModule readlineM = runtime.fastGetModule("Readline");

    readlineM.defineModuleFunction("readline", new Callback() {
        public IRubyObject execute(IRubyObject recv, IRubyObject[] args,
                                   Block block) {
            String line = readLine(args[0].toString());
            if (line != null) {
                return RubyString.newUnicodeString(runtime, line);
            } else {
                return runtime.getNil();
            }
        }

        public Arity getArity() {
            return Arity.twoArguments();
        }
    });
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:32,代码来源:TextAreaReadline.java

示例10: evaluate

import org.jruby.Ruby; //导入依赖的package包/类
public Object evaluate(final String expression, final Map<String, ?> values) throws ExpressionEvaluationException {
    LOG.debug("Evaluating JRuby expression: {1}", expression);
    try {
        final RubyInstanceConfig config = new RubyInstanceConfig();
        config.setCompatVersion(CompatVersion.RUBY1_9);
        final Ruby runtime = JavaEmbedUtils.initialize(new ArrayList<String>(), config);

        final StringBuilder localVars = new StringBuilder();
        for (final Entry<String, ?> entry : values.entrySet()) {
            runtime.getGlobalVariables().set("$" + entry.getKey(), JavaEmbedUtils.javaToRuby(runtime, entry.getValue()));
            localVars.append(entry.getKey()) //
                .append("=$") //
                .append(entry.getKey()) //
                .append("\n");
        }
        final IRubyObject result = runtime.evalScriptlet(localVars + expression);
        return JavaEmbedUtils.rubyToJava(runtime, result, Object.class);
    } catch (final RuntimeException ex) {
        throw new ExpressionEvaluationException("Evaluating JRuby expression failed: " + expression, ex);
    }
}
 
开发者ID:sebthom,项目名称:oval,代码行数:22,代码来源:ExpressionLanguageJRubyImpl.java

示例11: ScriptManager

import org.jruby.Ruby; //导入依赖的package包/类
private ScriptManager(String path) {
    this.basePath = path;
    this.packages = new LinkedList<Package>();
    this.ruby = new ScriptingContainer();
    this.commands = new HashMap<String, TextCommand>();
    this.items = new HashMap<String, ItemBehavior>();
    this.mobiles = new HashMap<String, MobileBehavior>();
    this.spells = new HashMap<Spell, SpellHandler>();

    log.config("Using Ruby " + ruby.getCompatVersion());
    Ruby.setThreadLocalRuntime(ruby.getProvider().getRuntime());
    ruby.setCompileMode(CompileMode.FORCE);
    ruby.runScriptlet("require 'yaml'");
    ruby.runScriptlet("java_import " + ScriptAPI.class.getName());
    ruby.runScriptlet("java_import " + ItemBehavior.class.getName());
    ruby.runScriptlet("java_import " + MobileBehavior.class.getName());
    ruby.runScriptlet("java_import " + TextCommand.class.getName());
    ruby.runScriptlet("java_import " + SpellHandler.class.getName());

    // Enumerations
    ruby.runScriptlet("java_import " + Spell.class.getName());
    ruby.runScriptlet("java_import " + Attribute.class.getName());
}
 
开发者ID:necr0potenc3,项目名称:uosl,代码行数:24,代码来源:ScriptManager.java

示例12: enter

import org.jruby.Ruby; //导入依赖的package包/类
@Override
public Object enter( String entryPointName, Executable executable, ExecutionContext executionContext, Object... arguments ) throws NoSuchMethodException, ParsingException, ExecutionException
{
	entryPointName = toRubyStyle( entryPointName );
	Ruby rubyRuntime = getRubyRuntime( executionContext );

	// Note that we're using the shared compilerRuntime to do the
	// conversions, so that we can cache Java proxies. It's very, very
	// slow if we have to generate them on the fly every time!

	IRubyObject[] rubyArguments = JavaUtil.convertJavaArrayToRuby( compilerRuntime, arguments );
	try
	{
		IRubyObject value = rubyRuntime.getTopSelf().callMethod( rubyRuntime.getCurrentContext(), entryPointName, rubyArguments );
		return value.toJava( Object.class );
	}
	catch( RaiseException x )
	{
		throw createExecutionException( x );
	}
	finally
	{
		rubyRuntime.getOut().flush();
		rubyRuntime.getErr().flush();
	}
}
 
开发者ID:tliron,项目名称:scripturian,代码行数:27,代码来源:JRubyAdapter.java

示例13: afterExecute

import org.jruby.Ruby; //导入依赖的package包/类
/**
 * afterExecute
 */
protected void afterExecute()
{
	Ruby runtime = this.getRuntime();

	// register any bundle libraries that were loaded by this script
	this.registerLibraries(runtime, this.getCommand().getPath());

	// unapply load paths
	this.unapplyLoadPaths(runtime);

	// unapply streams
	this.unapplyStreams();

	// unapply environment
	this.unapplyEnvironment();
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:20,代码来源:CommandBlockRunner.java

示例14: applyStreams

import org.jruby.Ruby; //导入依赖的package包/类
/**
 * applyStreams
 * 
 * @param container
 */
protected void applyStreams()
{
	Ruby runtime = this.getRuntime();
	CommandContext context = this.getContext();

	// turn off verbose mode (and warnings)
	boolean isVerbose = runtime.isVerbose();
	runtime.setVerbose(runtime.getNil());

	// set stdin/out/err and console
	this._oldReader = this.setReader(context.getInputStream());
	this._oldWriter = this.setWriter(context.getOutputStream());
	this._oldErrorWriter = this.setErrorWriter(context.getErrorStream());
	this._oldConsole = this.setConsole(context.getConsoleStream());

	// restore verbose mode
	runtime.setVerbose((isVerbose) ? runtime.getTrue() : runtime.getFalse());
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:24,代码来源:CommandBlockRunner.java

示例15: beforeExecute

import org.jruby.Ruby; //导入依赖的package包/类
/**
 * beforeExecute
 * 
 * @return
 */
protected void beforeExecute()
{
	Ruby runtime = this.getRuntime();

	// apply load paths
	this.applyLoadPaths(runtime);

	// apply streams
	this.applyStreams();

	// setup ENV
	this.applyEnvironment();

	// set default output type, this may be changed by context.exit_with_message
	this.getContext().setOutputType(this.getCommand().getOutputType());
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:22,代码来源:CommandBlockRunner.java


注:本文中的org.jruby.Ruby类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。