Package org.jruby

Examples of org.jruby.RubyFixnum


        return value;
    }
   
    @JRubyMethod(backtrace = true)
    public IRubyObject at(ThreadContext context, IRubyObject indexObj) {
        RubyFixnum lengthF = getJavaArray().length();
        RubyInteger indexI = indexObj.convertToInteger();
       
        if (indexI.getLongValue() < 0) {
            indexI = RubyFixnum.newFixnum(context.getRuntime(), indexI.getLongValue() + lengthF.getLongValue());
        }
        long index = indexI.getLongValue();
       
        if (index >= 0 && index < lengthF.getLongValue()) {
            return getJavaArray().arefDirect((int)indexI.getLongValue());
        } else {
            return context.getRuntime().getNil();
        }
    }
View Full Code Here


     */
    @JRubyMethod
    public RubyFixnum index(ThreadContext context, IRubyObject arg) {
        if (arg instanceof RubyString) {
            try {
                return new RubyFixnum(context.getRuntime(), internalSchema.getPosition(arg.toString()));
            } catch (FrontendException e) {
                throw new RuntimeException("Unable to find position for argument: " + arg);
            }
        } else {
            throw new RuntimeException("Invalid arguement passed to index: " + arg);
View Full Code Here

     * @param context the context the method is being executed in
     * @return        the size of the encapsulated Schema
     */
    @JRubyMethod(name = {"size", "length"})
    public RubyFixnum size(ThreadContext context) {
        return new RubyFixnum(context.getRuntime(), internalSchema.size());
    }
View Full Code Here

        RubyProc p = RubyProc.newProc(runtime, block, block.type);
        return p;
    }

    public static long ll2inum(Ruby runtime, long l) {
        RubyFixnum n = RubyFixnum.newFixnum(runtime, l);
        Handle h = GC.lookup(n);
        if (h != null) {
            return h.getAddress();
        }
        h = Handle.newHandle(runtime, n, Native.getInstance(runtime).newFixnumHandle(n, l));
View Full Code Here

                return;
            case ClassIndex.FALSE:
                write('F');
                return;
            case ClassIndex.FIXNUM: {
                RubyFixnum fixnum = (RubyFixnum)value;

                if (isMarshalFixnum(fixnum)) {
                    write('i');
                    writeInt((int) fixnum.getLongValue());
                    return;
                }
                // FIXME: inefficient; constructing a bignum just for dumping?
                value = RubyBignum.newBignum(value.getRuntime(), fixnum.getLongValue());

                // fall through
            }
            case ClassIndex.BIGNUM:
                write('l');
View Full Code Here

    public void userMarshal(IRubyObject value) throws IOException {
        userCommon(value, null);
    }

    private void userCommon(IRubyObject value, DynamicMethod method) throws IOException {
        RubyFixnum depthLimitFixnum = runtime.newFixnum(depthLimit);

        IRubyObject dumpResult;
        if (method != null) {
            dumpResult = method.call(runtime.getCurrentContext(), value, value.getMetaClass(), "_dump", depthLimitFixnum);
        } else {
View Full Code Here

    public final Encoding getEncoding(int index) {
        return encodings[index];
    }

    public final RubyFixnum getFixnum(ThreadContext context, int index, int value) {
        RubyFixnum fixnum = fixnums[index];
        if (fixnum == null) {
            return fixnums[index] = RubyFixnum.newFixnum(context.runtime, value);
        }
        return fixnum;
    }
View Full Code Here

        }
        return fixnum;
    }

    public final RubyFixnum getFixnum(ThreadContext context, int index, long value) {
        RubyFixnum fixnum = fixnums[index];
        if (fixnum == null) {
            return fixnums[index] = RubyFixnum.newFixnum(context.runtime, value);
        }
        return fixnum;
    }
View Full Code Here

        site.setTarget(handle);
        return site;
    }

    public static IRubyObject fixnum(MutableCallSite site, long value, ThreadContext context) {
        RubyFixnum fixnum = RubyFixnum.newFixnum(context.runtime, value);
        site.setTarget(Binder
                .from(IRubyObject.class, ThreadContext.class)
                .drop(0)
                .constant(fixnum)
        );
View Full Code Here

    public void testSetPreparedStatementParam() throws Exception {
        final PreparedStatement ps = context.mock(PreparedStatement.class);
        final Long num = Long.MAX_VALUE;
        final int idx = 0;
        final RubyFixnum fixnum = RubyFixnum.newFixnum(runtime, num);

        final AbstractDriverDefinition driver = new MyAbstractDriverDefinition();

        context.checking(new Expectations() {{
            allowing(ps).setLong(idx, num);
View Full Code Here

TOP

Related Classes of org.jruby.RubyFixnum

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.