core/src/main/java/org/jruby/RubyEnumerable.java
private static IRubyObject cycleCommon(ThreadContext context, IRubyObject self, long nv, final Block block) {
        final Ruby runtime = context.runtime;
        final List<IRubyObject> result = new ArrayList<>();

        each(context, eachSite(context), self, new JavaInternalBlockBody(runtime, Signature.OPTIONAL) {
            @Override
            public IRubyObject yield(ThreadContext context1, IRubyObject[] args) {
                return doYield(context1, null, packEnumValues(context1, args));
            }
            @Override
            public IRubyObject doYield(ThreadContext context1, Block unused, IRubyObject args) {
                synchronized (result) { result.add(args); }
                block.yield(context1, args);
                return context1.nil;
            }
        });

        int length = result.size();
        if (length == 0) return context.nil;

        while (nv < 0 || 0 < --nv) {
            for (int i = 0; i < length; i++) {
                block.yield(context, result.get(i));
            }
        }

        return context.nil;
    }
/*
     * @param nv number of times to cycle or -1 to cycle indefinitely
     */
@param nv number of times to cycle or -1 to cycle indefinitely
@param nv number of times to cycle or - 1 to cycle indefinitely
private static IRubyObject cycleCommon(ThreadContext context, IRubyObject self, long nv, final Block block) {
        final Ruby runtime = context.runtime;
        final List<IRubyObject> result = new ArrayList<>();
        each(context, eachSite(context), self, new JavaInternalBlockBody(runtime, Signature.OPTIONAL) {
            @Override
            public IRubyObject yield(ThreadContext context1, IRubyObject[] args) {
                return doYield(context1, null, packEnumValues(context1, args));
            }
            @Override
            public IRubyObject doYield(ThreadContext context1, Block unused, IRubyObject args) {
                synchronized (result) { result.add(args); }
                block.yield(context1, args);
                return context1.nil;
            }
        });
        int length = result.size();
        if (length == 0) return context.nil;
        while (nv < 0 || 0 < --nv) {
            for (int i = 0; i < length; i++) {
                block.yield(context, result.get(i));
            }
        }
        return context.nil;
    }
private static IRubyObject cycleCommon ( ThreadContext context , IRubyObject self , long nv , final Block block ) { final Ruby runtime = context . runtime ; final List < IRubyObject > result = new ArrayList < > ( ) ; each ( context , eachSite ( context ) , self , new JavaInternalBlockBody ( runtime , Signature . OPTIONAL ) { @ Override public IRubyObject yield ( ThreadContext context1 , IRubyObject [ ] args ) { return doYield ( context1 , null , packEnumValues ( context1 , args ) ) ; } @ Override public IRubyObject doYield ( ThreadContext context1 , Block unused , IRubyObject args ) { synchronized ( result ) { result . add ( args ) ; } block . yield ( context1 , args ) ; return context1 . nil ; } } ) ; int length = result . size ( ) ; if ( length == 0 ) return context . nil ; while ( nv < 0 || 0 < -- nv ) { for ( int i = 0 ; i < length ; i ++ ) { block . yield ( context , result . get ( i ) ) ; } } return context . nil ; }
@param nv number of times to cycle or -1 to cycle indefinitely
@param nv number of times to cycle or - 1 to cycle indefinitely