Exemple #1
0
 // c: random_dump
 @JRubyMethod(name = "marshal_dump")
 public IRubyObject marshal_dump(ThreadContext context) {
   RubyBignum state = random.getState();
   RubyInteger left = (RubyInteger) RubyNumeric.int2fix(context.runtime, random.getLeft());
   RubyArray dump = RubyArray.newArray(context.runtime, state, left, random.getSeed());
   if (hasVariables()) {
     dump.syncVariables(this);
   }
   return dump;
 }
 @JRubyMethod(name = {"<=>"})
 public IRubyObject compare(ThreadContext ctx, IRubyObject other) {
   Ruby runtime = ctx.getRuntime();
   if (!other.respondsTo("to_der")) return runtime.getNil();
   return RubyNumeric.int2fix(
       runtime,
       RubyAsn1.compareSetOfOrder(
           runtime,
           to_der(ctx).asString().getBytes(),
           Streams.toDer(other).asString().getBytes()));
 }
Exemple #3
0
    @JRubyMethod
    public synchronized IRubyObject select(
        ThreadContext context, IRubyObject timeout, Block block) {
      Ruby runtime = context.getRuntime();

      if (!this.selector.isOpen()) {
        throw context.getRuntime().newIOError("selector is closed");
      }

      int ready = doSelect(runtime, context, timeout);

      /* Timeout or wakeup */
      if (ready <= 0) return context.nil;

      RubyArray array = null;
      if (!block.isGiven()) {
        array = runtime.newArray(this.selector.selectedKeys().size());
      }

      Iterator selectedKeys = this.selector.selectedKeys().iterator();
      while (selectedKeys.hasNext()) {
        SelectionKey key = (SelectionKey) selectedKeys.next();
        processKey(key);
        selectedKeys.remove();

        if (block.isGiven()) {
          block.call(context, (IRubyObject) key.attachment());
        } else {
          array.add(key.attachment());
        }
      }

      if (block.isGiven()) {
        return RubyNumeric.int2fix(runtime, ready);
      } else {
        return array;
      }
    }
Exemple #4
0
 @JRubyMethod(name = {"length", "size"})
 public synchronized RubyNumeric length(ThreadContext context) {
   checkShutdown(context);
   return RubyNumeric.int2fix(context.runtime, entries.size());
 }
Exemple #5
0
 // c: random_s_left
 @JRubyMethod(name = "left", meta = true, visibility = PRIVATE)
 public static IRubyObject left(ThreadContext context, IRubyObject recv) {
   return RubyNumeric.int2fix(context.runtime, getDefaultRand(context).getLeft());
 }
Exemple #6
0
 // c: random_left
 @JRubyMethod(name = "left", visibility = PRIVATE)
 public IRubyObject leftObj(ThreadContext context) {
   return RubyNumeric.int2fix(context.runtime, random.getLeft());
 }