Examples of RubyObject


Examples of org.cx4a.rsense.ruby.RubyObject

    }

    public IRubyObject newMonomorphicInstance(Ruby runtime, RubyClass klass) {
        IRubyObject instance = instances.get(klass);
        if (instance == null) {
            instance = new RubyObject(runtime, klass);
            instances.put(klass, instance);
        }
        return instance;
    }
View Full Code Here

Examples of org.jruby.RubyObject

            } else if (type == Short.class) {
                return new Short(number.shortValue());
            }
        }
        if (isDuckTypeConvertable(argument.getClass(), parameterType)) {
            RubyObject rubyObject = (RubyObject) argument;
            if (!rubyObject.respondsTo("java_object")) {
                return convertProcToInterface(runtime.getCurrentContext(), rubyObject, parameterType);
            }
        }
        return argument;
    }
View Full Code Here

Examples of org.jruby.RubyObject

        }
    }
   
    public static Object coerceJavaObjectToType(ThreadContext context, Object javaObject, Class target) {
        if (javaObject != null && isDuckTypeConvertable(javaObject.getClass(), target)) {
            RubyObject rubyObject = (RubyObject) javaObject;
            if (!rubyObject.respondsTo("java_object")) {
                return convertProcToInterface(context, rubyObject, target);
            }

            // can't be converted any more, return it
            return javaObject;
View Full Code Here

Examples of org.jruby.RubyObject

   
    public static Object coerceOtherToType(ThreadContext context, IRubyObject arg, Class target) {
        Ruby runtime = context.getRuntime();
       
        if (isDuckTypeConvertable(arg.getClass(), target)) {
            RubyObject rubyObject = (RubyObject) arg;
            if (!rubyObject.respondsTo("java_object")) {
                return convertProcToInterface(context, rubyObject, target);
            }
        } else if (arg.respondsTo("to_java_object")) {
            Object javaObject = arg.callMethod(context, "to_java_object");
            if (javaObject instanceof JavaObject) {
View Full Code Here

Examples of org.jruby.RubyObject

                final RubyHash vars = (RubyHash)(((JRubyConstructor)ctor).constructRubyMapping(node));
                return RuntimeHelpers.invoke(runtime.getCurrentContext(), objClass, "new", runtime.newString(tag), vars);
            }
        }
        final RubyClass theCls = (RubyClass)objClass;
        final RubyObject oo = (RubyObject)theCls.getAllocator().allocate(runtime, theCls);
        final Map vars = (Map)(ctor.constructMapping(node));
        ctor.doRecursionFix(node, oo);
        for(final Iterator iter = vars.keySet().iterator();iter.hasNext();) {
            final IRubyObject key = (IRubyObject)iter.next();
            final Object val = vars.get(key);
            if(val instanceof LinkNode) {
                final String KEY = "@" + key.toString();
                ctor.addFixer((Node)(((LinkNode)val).getValue()), new RecursiveFixer() {
                        public void replace(Node node, Object real) {
                            oo.setInstanceVariable(KEY,(IRubyObject)real);
                        }
                    });
            } else {
                oo.setInstanceVariable("@" + key.toString(),(IRubyObject)val);
            }
        }
        return oo;
    }
View Full Code Here

Examples of org.jruby.RubyObject

        final Ruby runtime = ((JRubyConstructor)ctor).runtime;
        if(theCls.respondsTo("yaml_new")) {
            final RubyHash vars = (RubyHash)(((JRubyConstructor)ctor).constructRubyMapping(node));
            return RuntimeHelpers.invoke(runtime.getCurrentContext(), theCls, "yaml_new", theCls, runtime.newString(node.getTag()), vars);
        } else {
            final RubyObject oo = (RubyObject)theCls.getAllocator().allocate(runtime, theCls);
            if (oo.respondsTo("yaml_initialize")) {
                RubyHash vars = (RubyHash)(((JRubyConstructor)ctor).constructRubyMapping(node));
                RuntimeHelpers.invoke(runtime.getCurrentContext(), oo, "yaml_initialize", runtime.newString(node.getTag()), vars);
            } else {
                final Map vars = (Map)(ctor.constructMapping(node));
                ctor.doRecursionFix(node, oo);
                for(final Iterator iter = vars.keySet().iterator();iter.hasNext();) {
                    final IRubyObject key = (IRubyObject)iter.next();
                    final Object val = vars.get(key);
                    if(val instanceof LinkNode) {
                        final String KEY = "@" + key.toString();
                        ctor.addFixer((Node)(((LinkNode)val).getValue()), new RecursiveFixer() {
                                public void replace(Node node, Object real) {
                                    oo.setInstanceVariable(KEY,(IRubyObject)real);
                                }
                            });
                    } else {
                        oo.setInstanceVariable("@" + key.toString(),(IRubyObject)val);
                    }
                }
            }
            return oo;
        }
View Full Code Here

Examples of org.jruby.RubyObject

            for(int i=0,j=nms.length;i<j;i++) {
                objClass = (RubyModule)objClass.getConstant(nms[i]);
            }
        }
        final RubyClass theCls = (RubyClass)objClass;
        final RubyObject oo = (RubyObject)theCls.getAllocator().allocate(runtime, theCls);
        final IRubyObject val = (IRubyObject)constructYamlInt(ctor, node);
        oo.callInit(new IRubyObject[]{val},org.jruby.runtime.Block.NULL_BLOCK);
        return oo;
    }
View Full Code Here

Examples of org.jruby.RubyObject

    }

    @JRubyMethod(name = "new", rest = true, frame = true, meta = true)
    public static IRubyObject new_instance(IRubyObject self, IRubyObject[] args, Block block) {
        // Generator#new
        IRubyObject result = new RubyObject(self.getRuntime(),(RubyClass)self);
        result.dataWrapStruct(new GeneratorData(result));
        result.callMethod(self.getRuntime().getCurrentContext(), "initialize", args, block);
        return result;
    }
View Full Code Here

Examples of org.jruby.RubyObject

            for(int i=0,j=nms.length;i<j;i++) {
                objClass = (RubyModule)objClass.getConstant(nms[i]);
            }
        }
        final RubyClass theCls = (RubyClass)objClass;
        final RubyObject oo = (RubyObject)theCls.getAllocator().allocate(runtime, theCls);
        final IRubyObject val = (IRubyObject)constructYamlStr(ctor, node);
        oo.callInit(new IRubyObject[]{val},org.jruby.runtime.Block.NULL_BLOCK);
        return oo;
    }
View Full Code Here

Examples of org.jruby.RubyObject

            for(int i=0,j=nms.length;i<j;i++) {
                objClass = (RubyModule)objClass.getConstant(nms[i]);
            }
        }
        final RubyClass theCls = (RubyClass)objClass;
        final RubyObject oo = (RubyObject)theCls.getAllocator().allocate(runtime, theCls);
        final Map vars = (Map)(ctor.constructMapping(node));
        for(final Iterator iter = vars.keySet().iterator();iter.hasNext();) {
            final IRubyObject key = (IRubyObject)iter.next();
            RuntimeHelpers.invoke(oo.getRuntime().getCurrentContext(), oo, "[]=", key, (IRubyObject)vars.get(key));
        }
        return oo;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.