use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.
the class XmlComment method init.
@Override
protected void init(ThreadContext context, IRubyObject[] args) {
if (args.length < 2)
throw getRuntime().newArgumentError(args.length, 2);
IRubyObject doc = args[0];
IRubyObject text = args[1];
XmlDocument xmlDoc = null;
if (doc instanceof XmlDocument) {
xmlDoc = (XmlDocument) doc;
} else if (doc instanceof XmlNode) {
XmlNode xmlNode = (XmlNode) doc;
xmlDoc = (XmlDocument) xmlNode.document(context);
} else {
throw getRuntime().newArgumentError("first argument must be a XML::Document or XML::Node");
}
if (xmlDoc != null) {
Document document = xmlDoc.getDocument();
Node node = document.createComment(rubyStringToString(text));
setNode(context, node);
}
}
use of org.jruby.runtime.builtin.IRubyObject 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.runtime.builtin.IRubyObject 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.runtime.builtin.IRubyObject 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.runtime.builtin.IRubyObject 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