use of org.jruby.RubyProc in project enumerable by hraberg.
the class GroovyTest method interactingWithJRuby.
@Test
public void interactingWithJRuby() throws Exception {
ScriptEngine rb = JRubyTest.getJRubyEngine();
RubyProc proc = (RubyProc) rb.eval(":*.to_proc");
Closure<?> closure = toClosure(LambdaJRuby.toFn2(proc));
groovy.put("f", closure);
assertEquals(6L, groovy.eval("f(2, 3)"));
}
use of org.jruby.RubyProc in project enumerable by hraberg.
the class ClojureTest method interactingWithJRuby.
@Test
public void interactingWithJRuby() throws Exception {
ScriptEngine rb = JRubyTest.getJRubyEngine();
RubyProc proc = (RubyProc) rb.eval(":*.to_proc");
IFn times = toIFn(LambdaJRuby.toFn2(proc));
assertEquals(6L, times.invoke(2, 3));
defn("times-rb", times);
assertEquals(120L, clj.eval("(reduce times-rb 1 [1, 2, 3, 4, 5])"));
}
use of org.jruby.RubyProc 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;
}
}
use of org.jruby.RubyProc 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"));
}
use of org.jruby.RubyProc in project enumerable by hraberg.
the class JRubyTest method convertRubyMethodProcToFn.
@Test
public void convertRubyMethodProcToFn() throws ScriptException {
RubyProc proc = (RubyProc) rb.eval("(\"hello\".method :upcase).to_proc");
assertEquals("HELLO", toFn0(proc).call());
}
Aggregations