Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 import org.jruby.Ruby;
A shim class created when constructing primitive arrays from proxied Java classes. In the following code: Java::byte[50].new The [50] call produces an instance of ArrayJavaProxyCreator. The [] method can be called with any number of integer arguments to create a multi-dimensional array creator, or calls to [] can be chained for the same effect. The eventual call to new is against the ArrayJavaProxyCreator instance, and the result is a wrapped Java array of the specified dimensions and element type of the original receiver (the byte class, above).
public class ArrayJavaProxyCreator extends RubyObject {
    private static final int[] EMPTY = new int[0];
    int[] dimensions = ;
    public static RubyClass createArrayJavaProxyCreator(ThreadContext context) {
        Ruby runtime = context.runtime;
        RubyClass arrayJavaProxyCreator = runtime.defineClass("ArrayJavaProxyCreator"runtime.getObject(), .);
        return arrayJavaProxyCreator;
    public ArrayJavaProxyCreator(Ruby runtime) {
    public void setup(ThreadContext contextIRubyObject javaClassIRubyObject[] sizes) {
         = (ClassjavaClass.toJava(Class.class);
    @JRubyMethod(required = 1, rest = true)
    public IRubyObject op_aref(ThreadContext contextIRubyObject[] sizes) {
        Arity.checkArgumentCount(context.runtimesizes, 1, -1);
        return this;
    @JRubyMethod(name = "new")
    public IRubyObject _new(ThreadContext context) {
        Ruby runtime = context.runtime;
        Object array = Array.newInstance();
        return new ArrayJavaProxy(runtime, Java.getProxyClassForObject(runtimearray), array);
    private void aggregateDimensions(IRubyObject[] sizes) {
        int[] newDimensions = new int[. + sizes.length];
        System.arraycopy(, 0, newDimensions, 0, .);
        for (int i = 0; i < sizes.lengthi++) {
            IRubyObject size = sizes[i];
            int intSize = (intsize.convertToInteger().getLongValue();
            newDimensions[i + .] = intSize;
         = newDimensions;
New to GrepCode? Check out our FAQ X