Package org.jruby.runtime

Examples of org.jruby.runtime.JavaInternalBlockBody


    public static IRubyObject any_pCommon(ThreadContext context, IRubyObject self, final Block block) {
        final Ruby runtime = context.runtime;

        try {
            if (block.isGiven()) {
                each(context, self, new JavaInternalBlockBody(context, "Enumerable#any?", block.arity()) {
                    public IRubyObject yield(ThreadContext context, IRubyObject arg) {
                        if (block.yield(context, arg).isTrue()) throw JumpException.SPECIAL_JUMP;
                        return runtime.getNil();
                    }
                });
            } else {
                each(context, self, new JavaInternalBlockBody(context, "Enumerable#any?", Arity.ONE_REQUIRED) {
                    public IRubyObject yield(ThreadContext context, IRubyObject arg) {
                        if (arg.isTrue()) throw JumpException.SPECIAL_JUMP;
                        return runtime.getNil();
                    }
                });
View Full Code Here


    private static IRubyObject countCommon(ThreadContext context, IRubyObject self, final Block block, Arity callbackArity) {
        final Ruby runtime = context.runtime;
        final int result[] = new int[] { 0 };
       
        if (block.isGiven()) {
            each(context, self, new JavaInternalBlockBody(runtime, context, "Enumerable#count", block.arity()) {
                public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
                    IRubyObject packedArg = packEnumValues(context.runtime, args);
                    if (block.yield(context, packedArg).isTrue()) result[0]++;
                    return runtime.getNil();
                }
            });
        } else {
            each(context, self, new JavaInternalBlockBody(runtime, context, "Enumerable#count", Arity.NO_ARGUMENTS) {
                public IRubyObject yield(ThreadContext context, IRubyObject[] unusedValue) {
                    result[0]++;
                    return runtime.getNil();
                }
            });
View Full Code Here

        final Ruby runtime = context.runtime;
        final int result[] = new int[] { 0 };
       
        if (block.isGiven()) runtime.getWarnings().warn(ID.BLOCK_UNUSED , "given block not used");
       
        each(context, self, new JavaInternalBlockBody(runtime, context, "Enumerable#count", Arity.ONE_REQUIRED) {
            public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
                IRubyObject packedArg = packEnumValues(context.runtime, args);
                if (packedArg.equals(methodArg)) result[0]++;
               
                return runtime.getNil();
View Full Code Here

     */
    private static IRubyObject cycleCommon(ThreadContext context, IRubyObject self, long nv, final Block block) {
        final Ruby runtime = context.runtime;
        final RubyArray result = runtime.newArray();

        each(context, self, new JavaInternalBlockBody(runtime, Arity.OPTIONAL) {
            public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
                IRubyObject packedArg = packEnumValues(context.runtime, args);
                synchronized (result) { result.append(packedArg); }
                block.yield(context, packedArg);
                return runtime.getNil();           
View Full Code Here

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

        final RubyArray result = runtime.newArray();

        try {
            each(context, self, new JavaInternalBlockBody(runtime, Arity.ONE_REQUIRED) {
                long i = len; // Atomic ?
                public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
                    synchronized (result) {
                        IRubyObject packedArg = packEnumValues(context.runtime, args);
                        result.append(packedArg);
View Full Code Here

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

        final RubyArray result = runtime.newArray();

        try {
            each(context, self, new JavaInternalBlockBody(runtime, Arity.NO_ARGUMENTS) {
                long i = len; // Atomic ?
                public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
                    IRubyObject packedArg = packEnumValues(context.runtime, args);
                    synchronized (result) {
                        if (i == 0) {
View Full Code Here

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

        try {
            each(context, self, new JavaInternalBlockBody(runtime, context, "Enumerable#drop_while", Arity.OPTIONAL) {
                boolean memo = false;
                public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
                    IRubyObject packedArg = packEnumValues(context.runtime, args);
                    if (!memo && !block.yield(context, packedArg).isTrue()) memo = true;
                    if (memo) synchronized (result) { result.append(packedArg); }
View Full Code Here

    @JRubyMethod(name = "first")
    public static IRubyObject first(ThreadContext context, IRubyObject self) {
        final IRubyObject[] holder = new IRubyObject[]{ context.runtime.getNil() };

        try {
            each(context, self, new JavaInternalBlockBody(context.runtime, context, null, Arity.ONE_REQUIRED) {
                public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
                    IRubyObject packedArg = packEnumValues(context.runtime, args);
                    holder[0] = packedArg;
                    throw JumpException.SPECIAL_JUMP;
                }
View Full Code Here

        if (firstCount < 0) throw runtime.newArgumentError("negative index");
        if (firstCount == 0) return result;

        try {
            each(context, self, new JavaInternalBlockBody(runtime, context, null, Arity.ONE_REQUIRED) {
                private int iter = RubyNumeric.fix2int(num);               
                public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
                    IRubyObject packedArg = packEnumValues(context.runtime, args);
                    result.append(packedArg);
                    if (iter-- == 1) throw JumpException.SPECIAL_JUMP;
View Full Code Here

        if (self instanceof RubyArray) {
            RubyArray selfArray = (RubyArray) self;
            final IRubyObject[][] valuesAndCriteriaArray = new IRubyObject[selfArray.size()][2];

            each(context, self, new JavaInternalBlockBody(runtime, Arity.OPTIONAL) {
                AtomicInteger i = new AtomicInteger(0);
                public IRubyObject yield(ThreadContext context, IRubyObject[] args) {
                    IRubyObject packedArg = packEnumValues(context.runtime, args);
                    IRubyObject[] myVandC = valuesAndCriteriaArray[i.getAndIncrement()];
                    myVandC[0] = packedArg;
View Full Code Here

TOP

Related Classes of org.jruby.runtime.JavaInternalBlockBody

Copyright © 2018 www.massapicom. 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.