本文整理汇总了Java中org.jruby.RubyObject类的典型用法代码示例。如果您正苦于以下问题:Java RubyObject类的具体用法?Java RubyObject怎么用?Java RubyObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RubyObject类属于org.jruby包,在下文中一共展示了RubyObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createScriptInstance
import org.jruby.RubyObject; //导入依赖的package包/类
private void createScriptInstance(Script script) throws RaiseException
{
Logger.log(ScriptExecuter.class, Logger.DEBUG, "load Script: " + script.getKey());
if (script.getCode() == null || script.getCode().isEmpty())
{
Logger.log(ScriptExecuter.class, Logger.WARNING, "Script is empty: " + script.getKey());
return;
}
StringBuilder builder = new StringBuilder(script.getCode().length() + 32);
builder.append(script.getCode());
RubyObject scriptInstance = (RubyObject) eval(builder.toString());
// RubyObject scriptInstance = (RubyObject) scriptEngine.eval(builder.toString());
if (scriptInstance == null) return;
instanceCache.put(script.getKey(), scriptInstance);
// runtime.defineVariable(new GlobalVariable(runtime, "OBJ_" + script.getKey(), scriptInstance), runtime.g);
runtime.defineGlobalConstant("OBJ_" + script.getKey(), scriptInstance);
// Erstelle eine Variable im Skript-Kontext
// scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("$script_" + script.getKey(), scriptInstance);
}
示例2: serialize
import org.jruby.RubyObject; //导入依赖的package包/类
public String serialize(RubyObject object) {
ruby.put("$obj", object);
Object res = ruby.runScriptlet("YAML::dump($obj)");
if(res instanceof String) {
return (String) res;
} else {
log.warning("Couldn't serialize " + object);
return "";
}
}
示例3: deserialize
import org.jruby.RubyObject; //导入依赖的package包/类
public RubyObject deserialize(String serialized) {
ruby.put("$ser", serialized);
Object res = ruby.runScriptlet("YAML::load($ser)");
if(res != null) {
return (RubyObject) toRubyObject(res);
} else {
log.warning("Couldn't deserialize ' " + serialized + "'");
return null;
}
}
示例4: setObjectProperty
import org.jruby.RubyObject; //导入依赖的package包/类
@Override
public void setObjectProperty(SLObject object, String name, IRubyObject value) {
if(!(value instanceof RubyObject)) {
throw new UnsupportedOperationException("can only store real RubyObjects");
}
object.setProperty(name, (RubyObject) value);
}
示例5: readObject
import org.jruby.RubyObject; //导入依赖的package包/类
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
this.observers = new CopyOnWriteArraySet<ObjectObserver>();
this.scriptProperties = new HashMap<String, RubyObject>();
int count = stream.readInt();
for(int i = 0; i < count; i++) {
String key = (String) stream.readObject();
String data = (String) stream.readObject();
RubyObject obj = ScriptManager.instance().deserialize(data);
scriptProperties.put(key, obj);
}
}
示例6: while
import org.jruby.RubyObject; //导入依赖的package包/类
/**
* Returns the TreeNode (or null if not found) for the given key
* starting at given root.
*/
@SuppressWarnings("unchecked") final TreeNode getTreeNode
(int h, RubyObject k, TreeNode p) {
RubyClass c = k.getMetaClass(); boolean kNotComparable = !k.respondsTo("<=>");
while (p != null) {
int dir, ph; RubyObject pk; RubyClass pc;
if ((ph = p.hash) == h) {
if ((pk = (RubyObject)p.key) == k || k.equals(pk))
return p;
if (c != (pc = (RubyClass)pk.getMetaClass()) ||
kNotComparable ||
(dir = rubyCompare(k, pk)) == 0) {
dir = (c == pc) ? 0 : c.getName().compareTo(pc.getName());
if (dir == 0) { // if still stuck, need to check both sides
TreeNode r = null, pl, pr;
// try to recurse on the right
if ((pr = p.right) != null && h >= pr.hash && (r = getTreeNode(h, k, pr)) != null)
return r;
// try to continue iterating on the left side
else if ((pl = p.left) != null && h <= pl.hash)
dir = -1;
else // no matching node found
return null;
}
}
}
else
dir = (h < ph) ? -1 : 1;
p = (dir > 0) ? p.right : p.left;
}
return null;
}
示例7: rubyCompare
import org.jruby.RubyObject; //导入依赖的package包/类
int rubyCompare(RubyObject l, RubyObject r) {
ThreadContext context = l.getMetaClass().getRuntime().getCurrentContext();
IRubyObject result;
try {
result = l.callMethod(context, "<=>", r);
} catch (RaiseException e) {
// handle objects "lying" about responding to <=>, ie: an Array containing non-comparable keys
if (context.runtime.getNoMethodError().isInstance(e.getException())) {
return 0;
}
throw e;
}
return result.isNil() ? 0 : RubyNumeric.num2int(result.convertToInteger());
}
示例8: getBlocks
import org.jruby.RubyObject; //导入依赖的package包/类
@Override
public List<AbstractBlock> getBlocks() {
List<AbstractBlock> rubyBlocks = delegate.getBlocks();
for (int i = 0; i < rubyBlocks.size(); i++) {
Object abstractBlock = rubyBlocks.get(i);
if (!(abstractBlock instanceof RubyArray) && !(abstractBlock instanceof AbstractNode)) {
RubyObject rubyObject = (RubyObject) abstractBlock;
rubyBlocks.set(i, (AbstractBlock) NodeConverter.createASTNode(rubyObject));
}
}
return rubyBlocks;
}
示例9: setEncoding
import org.jruby.RubyObject; //导入依赖的package包/类
private boolean setEncoding(ThreadContext context, IRubyObject data) {
if (data.getType().respondsTo("detect_encoding")) {
// in case of EncodingReader is used
// since EncodingReader won't respond to :to_io
NokogiriEncodingReaderWrapper reader = new NokogiriEncodingReaderWrapper(context, (RubyObject) data);
source.setByteStream(reader);
// data is EnocodingReader
if(reader.detectEncoding()) {
detected_encoding = reader.getEncoding();
source.setEncoding(detected_encoding.asJavaString());
}
return true;
}
return false;
}
示例10: isFromFragmentHandler
import org.jruby.RubyObject; //导入依赖的package包/类
private boolean isFromFragmentHandler() {
if (object != null && object instanceof RubyObject) {
RubyObject rubyObj = (RubyObject)object;
IRubyObject document = rubyObj.getInstanceVariable("@document");
if (document != null) {
String name = document.getMetaClass().getName();
if ("Nokogiri::XML::FragmentHandler".equals(name)) {
return true;
}
}
}
return false;
}
示例11: NokogiriEncodingReaderWrapper
import org.jruby.RubyObject; //导入依赖的package包/类
public NokogiriEncodingReaderWrapper(ThreadContext context, RubyObject encodingReader) {
this.context = context;
this.encodingReader = encodingReader;
this.ruby = context.getRuntime();
if (!RuntimeHelpers.invoke(context, encodingReader, "respond_to?", ruby.newSymbol("read").to_sym()).isTrue()
|| encodingReader.getInstanceVariable("@io") == null) {
throw ruby.newArgumentError("Argument doesn't respond to read or doesn't have instance variable @io");
}
}
示例12: getSuperType
import org.jruby.RubyObject; //导入依赖的package包/类
/**
* Return the AegisType for the superclass if this type's class, if any.
* @return
*/
public AegisType getSuperType() {
BeanTypeInfo inf = getTypeInfo();
Class<?> c = inf.getTypeClass();
if (c.isInterface() && c.getInterfaces().length == 1) {
c = c.getInterfaces()[0];
} else {
c = c.getSuperclass();
}
/*
* Don't dig any deeper than Object or Exception
*/
if (c != null && c != RubyObject.class && c != Object.class && c != Exception.class && c != RuntimeException.class
&& c != Enum.class && c != Serializable.class && c != Cloneable.class) {
TypeMapping tm = inf.getTypeMapping();
AegisType superType = tm.getType(c);
if (superType == null) {
// if we call createType, we know that we'll get a BeanType. */
superType = getTypeMapping().getTypeCreator().createType(c);
if (superType != null) {
tm.register(superType);
this.info.setExtension(true);
}
} else {
this.info.setExtension(true);
}
return superType;
} else {
return null;
}
}
示例13: determineType
import org.jruby.RubyObject; //导入依赖的package包/类
public AegisType determineType(Context context, Class<?> clazz) {
TypeMapping tm = context.getTypeMapping();
if (tm == null) {
tm = getTypeMapping();
}
AegisType type = tm.getType(clazz);
if (null != type) {
return type;
}
Class<?>[] interfaces = clazz.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
Class<?> anInterface = interfaces[i];
type = tm.getType(anInterface);
if (null != type) {
return type;
}
}
Class<?> superclass = clazz.getSuperclass();
if (null == superclass || Object.class.equals(superclass) || RubyObject.class.equals(superclass)) {
return null;
}
return determineType(context, superclass);
}
示例14: toJavaObject
import org.jruby.RubyObject; //导入依赖的package包/类
public static Object toJavaObject(Object rubyObject) {
if (rubyObject == null)
return null;
if (rubyObject instanceof RubyArray)
return toJavaArray((RubyArray) rubyObject);
if (rubyObject instanceof RubyHash)
return toJavaHash((RubyHash) rubyObject);
if (rubyObject instanceof RubyObject)
return ((RubyObject) rubyObject).toJava(Object.class);
return rubyObject.toString();
}
示例15: executeScript
import org.jruby.RubyObject; //导入依赖的package包/类
private Object executeScript(String name, String main, Object... args)
{
RubyObject scriptInstance = instanceCache.get(name);
if (scriptInstance == null)
{
Logger.log(ScriptExecuter.class, Logger.ERROR,
"Script-Instance for " + name + " do not exists.");
return null;
}
try
{
Logger.log(ScriptExecuter.class, Logger.DEBUG,
"execute script: " + name + "." + main);
// runtime.defineVariable( new GlobalVariable(runtime, "$trigger", toRubyObject(trigger)), Scope.THREAD);
IRubyObject result;
if (args != null && args.length > 0)
result = scriptInstance.callMethod(main, toRubyObject(args));
else
result = scriptInstance.callMethod(main);
return JavaEmbedUtils.rubyToJava(result);
}
catch (RaiseException e)
{
Logger.log(ScriptExecuter.class, Logger.ERROR, e);
return null;
}
}