Search in sources :

Example 1 with Ruby

use of org.jruby.Ruby in project qi4j-sdk by Qi4j.

the class JRubyMixinTest method assemble.

public void assemble(ModuleAssembly module) throws AssemblyException {
    module.transients(MyDomainType.class).withMixins(JRubyMixin.class);
    Ruby ruby = Ruby.newInstance();
    module.importedServices(Ruby.class).importedBy(InstanceImporter.class).setMetaInfo(ruby);
}
Also used : Ruby(org.jruby.Ruby) InstanceImporter(org.qi4j.api.service.importer.InstanceImporter)

Example 2 with Ruby

use of org.jruby.Ruby in project enumerable by hraberg.

the class JRubyTest method convertedRubyProcRaisesArgumentErrorWhenCalledWithTooFewArguments.

@Test(expected = RaiseException.class)
public void convertedRubyProcRaisesArgumentErrorWhenCalledWithTooFewArguments() throws ScriptException {
    Ruby ruby = Ruby.getGlobalRuntime();
    try {
        RubyProc proc = toProc(Lambda.λ(s, s.toUpperCase()));
        proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[0]);
    } catch (RaiseException e) {
        assertEquals(ruby.getArgumentError(), e.getException().getType());
        throw e;
    }
}
Also used : RubyProc(org.jruby.RubyProc) RaiseException(org.jruby.exceptions.RaiseException) Ruby(org.jruby.Ruby) LambdaJRuby(org.enumerable.lambda.support.jruby.LambdaJRuby) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Example 3 with Ruby

use of org.jruby.Ruby in project enumerable by hraberg.

the class JRubyTest method interactingWithScala.

@SuppressWarnings("unchecked")
@Test
public void interactingWithScala() throws Exception {
    Ruby ruby = Ruby.getGlobalRuntime();
    ScalaInterpreter scala = ScalaTest.getScalaInterpreter();
    Function2<Integer, Integer, Integer> f = (Function2<Integer, Integer, Integer>) scala.eval("(n: Long, m: Long) => n * m");
    RubyProc proc = toProc(LambdaScala.toFn2(f));
    assertEquals(ruby.newFixnum(6), proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[] { ruby.newFixnum(2), ruby.newFixnum(3) }));
    rb.put("block", proc);
    assertEquals(120L, rb.eval("[1, 2, 3, 4, 5].inject &block"));
}
Also used : RubyProc(org.jruby.RubyProc) ScalaInterpreter(org.enumerable.lambda.support.scala.ScalaTest.ScalaInterpreter) Function2(scala.Function2) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) LambdaJRuby(org.enumerable.lambda.support.jruby.LambdaJRuby) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Example 4 with Ruby

use of org.jruby.Ruby in project enumerable by hraberg.

the class JRubyTest method convertFnToRubyProc.

@Test
public void convertFnToRubyProc() throws ScriptException {
    Ruby ruby = Ruby.getGlobalRuntime();
    RubyProc proc = toProc(Lambda.λ(s, s.toUpperCase()));
    assertEquals(ruby.newString("HELLO"), proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[] { ruby.newString("hello") }));
}
Also used : RubyProc(org.jruby.RubyProc) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) LambdaJRuby(org.enumerable.lambda.support.jruby.LambdaJRuby) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Example 5 with Ruby

use of org.jruby.Ruby in project enumerable by hraberg.

the class JRubyTest method interactingWithGroovy.

@Test
public void interactingWithGroovy() throws Exception {
    Ruby ruby = Ruby.getGlobalRuntime();
    ScriptEngine groovy = GroovyTest.getGroovyEngine();
    Closure<?> closure = (Closure<?>) groovy.eval("{ n, m -> n * m }");
    RubyProc proc = toProc(LambdaGroovy.toFn2(closure));
    assertEquals(ruby.newFixnum(6), proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[] { ruby.newFixnum(2), ruby.newFixnum(3) }));
    rb.put("block", proc);
    assertEquals(120L, rb.eval("[1, 2, 3, 4, 5].inject &block"));
}
Also used : RubyProc(org.jruby.RubyProc) Closure(groovy.lang.Closure) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) LambdaJRuby(org.enumerable.lambda.support.jruby.LambdaJRuby) ScriptEngine(javax.script.ScriptEngine) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Aggregations

Ruby (org.jruby.Ruby)71 JRubyMethod (org.jruby.anno.JRubyMethod)31 IRubyObject (org.jruby.runtime.builtin.IRubyObject)26 RubyArray (org.jruby.RubyArray)13 RubyString (org.jruby.RubyString)10 ClojureTest (org.enumerable.lambda.support.clojure.ClojureTest)8 GroovyTest (org.enumerable.lambda.support.groovy.GroovyTest)8 JavaScriptTest (org.enumerable.lambda.support.javascript.JavaScriptTest)8 LambdaJRuby (org.enumerable.lambda.support.jruby.LambdaJRuby)8 ScalaTest (org.enumerable.lambda.support.scala.ScalaTest)8 RubyProc (org.jruby.RubyProc)8 Test (org.junit.Test)8 Document (org.w3c.dom.Document)8 InputStream (java.io.InputStream)6 NokogiriHelpers.clearCachedNode (nokogiri.internals.NokogiriHelpers.clearCachedNode)6 NokogiriHelpers.nodeArrayToRubyArray (nokogiri.internals.NokogiriHelpers.nodeArrayToRubyArray)6 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)6 Node (org.w3c.dom.Node)6 IOException (java.io.IOException)5 XmlDomParserContext (nokogiri.internals.XmlDomParserContext)5