use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.
the class XmlDomParserContext method wrapDocument.
/**
* This method is broken out so that HtmlDomParserContext can
* override it.
*/
protected XmlDocument wrapDocument(ThreadContext context, RubyClass klazz, Document doc) {
XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), klazz);
xmlDocument.setDocumentNode(context, doc);
xmlDocument.setEncoding(ruby_encoding);
if (options.dtdLoad) {
IRubyObject xmlDtdOrNil = XmlDtd.newFromExternalSubset(context.getRuntime(), doc);
if (!xmlDtdOrNil.isNil()) {
XmlDtd xmlDtd = (XmlDtd) xmlDtdOrNil;
doc.setUserData(XmlDocument.DTD_EXTERNAL_SUBSET, xmlDtd, null);
}
}
return xmlDocument;
}
use of org.jruby.runtime.builtin.IRubyObject in project cucumber-jvm by cucumber.
the class JRubyBackend method executeStepdef.
void executeStepdef(RubyObject stepdef, I18n i18n, Object[] args) {
ArrayList<IRubyObject> jrubyArgs = new ArrayList<IRubyObject>();
// jrubyWorld.@__gherkin_i18n = i18n
RubyObject jrubyI18n = (RubyObject) JavaEmbedUtils.javaToRuby(stepdef.getRuntime(), i18n);
currentWorld.callMethod("instance_variable_set", new IRubyObject[] { stepdef.getRuntime().newSymbol("@__gherkin_i18n"), jrubyI18n });
jrubyArgs.add(currentWorld);
for (Object o : args) {
if (o == null) {
jrubyArgs.add(null);
} else if (o instanceof DataTable) {
//Add a datatable as it stands...
jrubyArgs.add(JavaEmbedUtils.javaToRuby(stepdef.getRuntime(), o));
} else {
jrubyArgs.add(stepdef.getRuntime().newString((String) o));
}
}
stepdef.callMethod("execute", jrubyArgs.toArray(new IRubyObject[jrubyArgs.size()]));
}
use of org.jruby.runtime.builtin.IRubyObject in project cucumber-jvm by cucumber.
the class JRubyStepDefinition method matchedArguments.
@Override
public List<Argument> matchedArguments(Step step) {
RubyString stepName = stepdefRunner.getRuntime().newString(step.getName());
IRubyObject arguments = stepdefRunner.callMethod("matched_arguments", stepName);
return toJava(arguments);
}
use of org.jruby.runtime.builtin.IRubyObject in project enumerable by hraberg.
the class JRubyTest method interactingWithJavaScript.
@Test
public void interactingWithJavaScript() throws Exception {
Ruby ruby = Ruby.getGlobalRuntime();
ScriptEngine js = JavaScriptTest.getJavaScriptEngine();
Function f = (Function) js.eval("var f = function(n, m) { return n * m; }; f;");
RubyProc proc = toProc(LambdaJavaScript.toFn2(f));
assertEquals(ruby.newFloat(6), proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[] { ruby.newFixnum(2), ruby.newFixnum(3) }));
rb.put("block", proc);
assertEquals(120.0, 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 convertFnToRubyProcKeepsDefaultValues.
@Test
public void convertFnToRubyProcKeepsDefaultValues() throws ScriptException {
Ruby ruby = Ruby.getGlobalRuntime();
RubyProc proc = toProc(Lambda.λ(s = "world", s.toUpperCase()));
assertEquals(ruby.newString("WORLD"), proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[] {}));
}
Aggregations