Package org.jruby

Examples of org.jruby.RubyClass.allocate()


                    @Override
                    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
                        assert self instanceof RubyClass : "new defined on non-class";

                        RubyClass clazzSelf = (RubyClass)self;
                        IRubyObject newObj = clazzSelf.allocate();
                        RuntimeHelpers.invoke(context, newObj, "__jcreate!", args, block);
                        RuntimeHelpers.invoke(context, newObj, "initialize", args, block);

                        return newObj;
                    }
View Full Code Here


            @Override
            public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
                assert self instanceof RubyClass : "InterfaceJavaProxy.new defined on non-class ";
                RubyClass rubyClass = (RubyClass)self;

                IRubyObject proxy = rubyClass.allocate();
                JavaClass javaClass = (JavaClass)RuntimeHelpers.invoke(context, proxy.getMetaClass(), "java_class");
                IRubyObject proxyInstance = Java.new_proxy_instance2(
                        self,
                        self,
                        RubyArray.newArray(context.getRuntime(), javaClass),
View Full Code Here

    }

    private IRubyObject userNewUnmarshal() throws IOException {
        String className = unmarshalObject().asJavaString();
        RubyClass classInstance = findClass(className);
        IRubyObject result = classInstance.allocate();
        registerLinkTarget(result);
        IRubyObject marshaled = unmarshalObject();
        result.callMethod(getRuntime().getCurrentContext(),"marshal_load", marshaled);
        return result;
    }
View Full Code Here

    }

    private IRubyObject userNewUnmarshal() throws IOException {
        String className = unmarshalObject(false).asJavaString();
        RubyClass classInstance = findClass(className);
        IRubyObject result = classInstance.allocate();
        registerLinkTarget(result);
        IRubyObject marshaled = unmarshalObject();
        return classInstance.smartLoadNewUser(result, marshaled);
    }
View Full Code Here

    // TODO add test methods here. The name must begin with 'test'. For example:
    public void testSetClassAllocator() {
        // start out with a default RubyObject allocator
        RubyClass newClass = runtime.defineClass("TestSetClassAllocatorClass", runtime.getObject(), runtime.getObject().getAllocator());

        assertEquals(RubyObject.class, newClass.allocate().getClass());

        // switch to an allocator based on a default constructor
        MyRubyObjectSubclass.currentRuntime = runtime;
        newClass.setClassAllocator(MyRubyObjectSubclass.class);
View Full Code Here

        // switch to an allocator based on a default constructor
        MyRubyObjectSubclass.currentRuntime = runtime;
        newClass.setClassAllocator(MyRubyObjectSubclass.class);

        assertEquals(MyRubyObjectSubclass.class, newClass.allocate().getClass());
    }
}
View Full Code Here

                    @Override
                    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
                        assert self instanceof RubyClass : "new defined on non-class";

                        RubyClass clazzSelf = (RubyClass) self;
                        IRubyObject newObj = clazzSelf.allocate();
                        RuntimeHelpers.invoke(context, newObj, "__jcreate!", args, block);
                        RuntimeHelpers.invoke(context, newObj, "initialize", args, block);

                        return newObj;
                    }
View Full Code Here

    }

    private IRubyObject userNewUnmarshal() throws IOException {
        String className = unmarshalObject(false).asJavaString();
        RubyClass classInstance = findClass(className);
        IRubyObject result = classInstance.allocate();
        registerLinkTarget(result);
        IRubyObject marshaled = unmarshalObject();
        return classInstance.smartLoadNewUser(result, marshaled);
    }
View Full Code Here

    };

    @JRubyMethod(name = "new", rest = true, meta = true)
    public static JZlibRubyGzipWriter newInstance(IRubyObject recv, IRubyObject[] args, Block block) {
        RubyClass klass = (RubyClass) recv;
        JZlibRubyGzipWriter result = (JZlibRubyGzipWriter) klass.allocate();
        result.callInit(args, block);
       
        return result;
    }
View Full Code Here

            level = RubyNumeric.fix2int(args[1]);
            checkLevel(runtime, level);
        }

        RubyClass klass = (RubyClass) recv;
        JZlibDeflate deflate = (JZlibDeflate) klass.allocate();
        deflate.init(level, JZlib.DEF_WBITS, 8, JZlib.Z_DEFAULT_STRATEGY);

        try {
            IRubyObject result = deflate.deflate(args[0].convertToString().getByteList(), JZlib.Z_FINISH);
            deflate.close();
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.