Examples of BlockCallback


Examples of org.jruby.runtime.BlockCallback

    @JRubyMethod(name = "detach", required = 1, module = true, visibility = Visibility.PRIVATE)
    public static IRubyObject detach(ThreadContext context, IRubyObject recv, IRubyObject arg) {
        final int pid = (int)arg.convertToInteger().getLongValue();
        Ruby runtime = recv.getRuntime();
       
        BlockCallback callback = new BlockCallback() {
            public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
                int[] status = new int[1];
                int result = context.getRuntime().getPosix().waitpid(pid, status, 0);
               
                return context.getRuntime().newFixnum(result);
View Full Code Here

Examples of org.jruby.runtime.BlockCallback

        if (size <= 0) throw self.getRuntime().newArgumentError("invalid slice size");

        final Ruby runtime = self.getRuntime();
        final RubyArray result[] = new RubyArray[]{runtime.newArray(size)};

        RubyEnumerable.callEach(runtime, context, self, new BlockCallback() {
            public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
                result[0].append(largs[0]);
                if (result[0].size() == size) {
                    block.yield(ctx, result[0]);
                    result[0] = runtime.newArray(size);
View Full Code Here

Examples of org.jruby.runtime.BlockCallback

        if (size <= 0) throw self.getRuntime().newArgumentError("invalid size");

        final Ruby runtime = self.getRuntime();
        final RubyArray result = runtime.newArray(size);

        RubyEnumerable.callEach(runtime, context, self, new BlockCallback() {
            public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
                if (result.size() == size) result.shift(ctx);
                result.append(largs[0]);
                if (result.size() == size) block.yield(ctx, result.aryDup());
                return runtime.getNil();
View Full Code Here

Examples of org.jruby.runtime.BlockCallback

        }
        if(oldHandler instanceof JRubySignalHandler) {
            return ((JRubySignalHandler)oldHandler).block;
        } else {
            return RubyProc.newProc(recv.getRuntime(), CallBlock.newCallClosure(recv, (RubyModule)recv,
                                                                                Arity.noArguments(), new BlockCallback(){
                                                                                        public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
                                                                                            oldHandler.handle(new Signal(handler.signal));
                                                                                            return recv.getRuntime().getNil();
                                                                                        }
                                                                                    }, recv.getRuntime().getCurrentContext()), Block.Type.NORMAL);
View Full Code Here

Examples of org.jruby.runtime.BlockCallback

        final ThreadContext localContext = context;
        final int result[];
       
        if (block.isGiven()) {
            result = new int[] { 0 };
            callEach(runtime, context, self, new BlockCallback() {
                public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
                    checkContext(localContext, ctx, "count");
                    if (block.yield(ctx, largs[0]).isTrue()) {
                        result[0]++;
                    }
                    return runtime.getNil();
                }
            });
        } else {
            if (self.respondsTo("size")) return self.callMethod(context, "size");

            result = new int[] { 0 };
            callEach(runtime, context, self, new BlockCallback() {
                public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
                    checkContext(localContext, ctx, "count");
                    result[0]++;
                    return runtime.getNil();
                }
View Full Code Here

Examples of org.jruby.runtime.BlockCallback

        final ThreadContext localContext = context;
        final int result[] = new int[] { 0 };
       
        if (block.isGiven()) runtime.getWarnings().warn(ID.BLOCK_UNUSED , "given block not used");
       
        callEach(runtime, context, self, new BlockCallback() {
            public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block block) {
                checkContext(localContext, ctx, "count");
                if (largs[0].equals(arg)) result[0]++;
                return runtime.getNil();
            }
View Full Code Here

Examples of org.jruby.runtime.BlockCallback

   
    private static IRubyObject cycleCommon(ThreadContext context, IRubyObject self, long nv, final Block block) {
        final Ruby runtime = context.getRuntime();
        final RubyArray result = runtime.newArray();
       
        callEach(runtime, context, self, new BlockCallback() {
            public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
                synchronized (result) {
                    result.append(largs[0]);
                }
                block.yield(ctx, largs[0]);
View Full Code Here

Examples of org.jruby.runtime.BlockCallback

        if (len == 0) return runtime.newEmptyArray();

        final RubyArray result = runtime.newArray();

        try {
            callEach(runtime, context, self, new BlockCallback() {
                long i = len; // Atomic ?
                public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
                    synchronized (result) {
                        result.append(largs[0]);
                        if (--i == 0) throw JumpException.SPECIAL_JUMP;
View Full Code Here

Examples of org.jruby.runtime.BlockCallback

        final Ruby runtime = context.getRuntime();
        final RubyArray result = runtime.newArray();

        try {
            callEach(runtime, context, self, new BlockCallback() {
                public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
                    if (!block.yield(ctx, largs[0]).isTrue()) throw JumpException.SPECIAL_JUMP;
                    synchronized (result) {
                        result.append(largs[0]);
                    }
View Full Code Here

Examples of org.jruby.runtime.BlockCallback

        if (len < 0) throw runtime.newArgumentError("attempt to drop negative size");

        final RubyArray result = runtime.newArray();

        try {
            callEach(runtime, context, self, new BlockCallback() {
                long i = len; // Atomic ?
                public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
                    synchronized (result) {
                        if (i == 0) {
                            result.append(largs[0]);
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.