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());
}
use of org.jruby.RubyProc 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") }));
}
use of org.jruby.RubyProc 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"));
}
use of org.jruby.RubyProc in project enumerable by hraberg.
the class JRubyTest method convertRubyMethodProcToFnKeepsDefaultValues.
@Test
public void convertRubyMethodProcToFnKeepsDefaultValues() throws ScriptException {
RubyProc proc = (RubyProc) rb.eval("def my_upcase(s = 'world') s.upcase end; method(:my_upcase).to_proc");
assertEquals("WORLD", toFn1(proc).call());
}
use of org.jruby.RubyProc in project enumerable by hraberg.
the class JRubyTest method interactingWithClojure.
@Test
public void interactingWithClojure() throws Exception {
Ruby ruby = Ruby.getGlobalRuntime();
IFn star = (IFn) ClojureTest.getClojureEngine().eval("*");
RubyProc proc = toProc(LambdaClojure.toFn2(star));
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"));
}
Aggregations