Exemplo n.º 1
0
  public static String convertToInteger(Object rubyObject) throws AxisFault {
    try {
      if (rubyObject instanceof RubyInteger) {
        RubyInteger intObject = (RubyInteger) rubyObject;
        return intObject.toString();
      }
      return Integer.toString(RubyInteger.num2int((IRubyObject) rubyObject));
      // return rubyObject.toString();

    } catch (Exception e) {
      throw new AxisFault("/Unable to convert the return value to integer");
    }
  }
Exemplo n.º 2
0
 // c: rand_int
 private static IRubyObject randInt(
     ThreadContext context, RandomType random, RubyInteger vmax, boolean restrictive) {
   if (vmax instanceof RubyFixnum) {
     long max = RubyNumeric.fix2long(vmax);
     if (max == 0) {
       return context.nil;
     }
     if (max < 0) {
       if (restrictive) {
         return context.nil;
       }
       max = -max;
     }
     return randLimitedFixnum(context, random, max - 1);
   } else {
     BigInteger big = vmax.getBigIntegerValue();
     if (big.equals(BigInteger.ZERO)) {
       return context.nil;
     }
     if (big.signum() < 0) {
       if (restrictive) {
         return context.nil;
       }
       big = big.abs();
     }
     big = big.subtract(BigInteger.ONE);
     return randLimitedBignum(context, random, RubyBignum.newBignum(context.runtime, big));
   }
 }
Exemplo n.º 3
0
 private static IRubyObject randCommon(ThreadContext context, RandomType random, RubyInteger max) {
   if (max.zero_p(context).isTrue()) {
     return randFloat(context, random);
   }
   IRubyObject r = randInt(context, random, max, false);
   if (r.isNil()) {
     return randFloat(context, random);
   }
   return r;
 }