Java Code Examples for org.jruby.javasupport.JavaEmbedUtils#rubyToJava()

The following examples show how to use org.jruby.javasupport.JavaEmbedUtils#rubyToJava() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RubyHashMapDecorator.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
private Object convertRubyValue(Object rubyValue) {
    if (rubyValue == null) {
        return null;
    } else if (rubyValue instanceof IRubyObject) {
        IRubyObject rubyObject = (IRubyObject) rubyValue;

        if (RubyClass.KindOf.DEFAULT_KIND_OF.isKindOf(rubyObject, getAbstractNodeClass())) {
            return NodeConverter.createASTNode(rubyObject);
        }
        if (rubyObject instanceof RubySymbol) {
            return ":" + rubyObject.asString();
        }
        return JavaEmbedUtils.rubyToJava((IRubyObject) rubyValue);
    } else {
        return rubyValue;
    }
}
 
Example 2
Source File: RubyScript.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void findAssertionProviderMethods() {
    IRubyObject ro = interpreter.evalScriptlet("Object.private_instance_methods");
    String[] methods = (String[]) JavaEmbedUtils.rubyToJava(interpreter, ro, String[].class);
    assertionProviderList = new ArrayList<String>();
    for (Object method : methods) {
        if (method.toString().startsWith("marathon_assert_")) {
            assertionProviderList.add(method.toString());
        }
    }
}
 
Example 3
Source File: JRubyScriptUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Object convertFromRuby(IRubyObject rubyResult, Class<?> returnType) {
	Object result = JavaEmbedUtils.rubyToJava(this.ruby, rubyResult, returnType);
	if (result instanceof RubyArray && returnType.isArray()) {
		result = convertFromRubyArray(((RubyArray) result).toJavaArray(), returnType);
	}
	return result;
}
 
Example 4
Source File: JRubyScriptUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private Object convertFromRuby(IRubyObject rubyResult, Class<?> returnType) {
	Object result = JavaEmbedUtils.rubyToJava(this.ruby, rubyResult, returnType);
	if (result instanceof RubyArray && returnType.isArray()) {
		result = convertFromRubyArray(((RubyArray) result).toJavaArray(), returnType);
	}
	return result;
}
 
Example 5
Source File: ExtensionGroupImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@JRubyMethod(name = "register_extensions", required = 2)
public IRubyObject registerExtensions(ThreadContext context, IRubyObject registry, IRubyObject rubyRegistrators) {
  List<Registrator> registrators = (List<Registrator>) JavaEmbedUtils.rubyToJava(rubyRegistrators);
  for (Registrator registrator: registrators) {
    registrator.register(registry);
  }
  return context.getRuntime().getNil();
}
 
Example 6
Source File: RubyHashUtil.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private static Object toJavaObject(Object rubyObject) {
    if (rubyObject instanceof IRubyObject) {
        IRubyObject iRubyObject = (IRubyObject) rubyObject;
        return JavaEmbedUtils.rubyToJava(iRubyObject);
    }

    return rubyObject;
}
 
Example 7
Source File: RubyAttributesMapDecorator.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private Object convertRubyValue(Object rubyValue) {
    if (rubyValue == null) {
        return null;
    } else if (rubyValue instanceof IRubyObject) {
        return JavaEmbedUtils.rubyToJava((IRubyObject) rubyValue);
    } else {
        return rubyValue;
    }
}
 
Example 8
Source File: RubyScript.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void readGlobals() {
    interpreter.evalScriptlet("RubyMarathon.new('" + driverURL + "')");
    IRubyObject marathon = interpreter.evalScriptlet("$marathon");
    interpreter.evalScriptlet("$test = proc { test }");
    runtime = (MarathonRuby) JavaEmbedUtils.rubyToJava(interpreter, marathon, MarathonRuby.class);
}
 
Example 9
Source File: ContentNodeImpl.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
@Override
public Object getAttribute(Object name, Object defaultValue, boolean inherit) {
    return JavaEmbedUtils.rubyToJava(getRubyProperty("attr", name, defaultValue, inherit));
}
 
Example 10
Source File: ContentNodeImpl.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
@Override
public Object getAttribute(Object name, Object defaultValue) {
    return JavaEmbedUtils.rubyToJava(getRubyProperty("attr", name, defaultValue));
}
 
Example 11
Source File: ContentNodeImpl.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
@Override
public Object getAttribute(Object name) {
    return JavaEmbedUtils.rubyToJava(getRubyProperty("attr", name));
}
 
Example 12
Source File: RubyObjectWrapper.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
public Object toJava(IRubyObject rubyObject) {
    return JavaEmbedUtils.rubyToJava(rubyObject);
}
 
Example 13
Source File: RubyObjectWrapper.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
public <T> T toJava(IRubyObject rubyObject, Class<T> targetClass) {
    return (T) JavaEmbedUtils.rubyToJava(runtime, rubyObject, targetClass);
}