org.jruby.Ruby.newFixnum()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(219)

本文整理了Java中org.jruby.Ruby.newFixnum方法的一些代码示例,展示了Ruby.newFixnum的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.newFixnum方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:newFixnum

Ruby.newFixnum介绍

暂无

代码示例

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod
public IRubyObject length(ThreadContext context) {
  return context.runtime.newFixnum(this.table.size());
}

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod
public IRubyObject each(ThreadContext context, Block block) {
  Ruby runtime = context.runtime;
  for (Descriptors.EnumValueDescriptor enumValueDescriptor : descriptor.getValues()) {
    block.yield(context, runtime.newArray(runtime.newSymbol(enumValueDescriptor.getName()),
        runtime.newFixnum(enumValueDescriptor.getNumber())));
  }
  return runtime.getNil();
}

代码示例来源:origin: bazelbuild/bazel

switch (fieldType) {
  case INT32:
    return runtime.newFixnum((Integer) value);
  case INT64:
    return runtime.newFixnum((Long) value);
  case UINT32:
    return runtime.newFixnum(((Integer) value) & (-1l >>> 32));
  case UINT64:
    long ret = (Long) value;
    return ret >= 0 ? runtime.newFixnum(ret) :
        RubyBignum.newBignum(runtime, UINT64_COMPLEMENTARY.add(new BigInteger(ret + "")));
  case FLOAT:
    return runtime.getNil();

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(required = 1)
public IRubyObject lchmod(ThreadContext context, IRubyObject arg) {
  int mode = (int) arg.convertToInteger().getLongValue();
  if (!new File(path).exists()) {
    throw context.runtime.newErrnoENOENTError(path);
  }
  return context.runtime.newFixnum(context.runtime.getPosix().lchmod(path, mode));
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
    int[] status = new int[1];
    Ruby runtime = context.runtime;
    int result = checkErrno(runtime, runtime.getPosix().waitpid(pid, status, 0));
    
    return runtime.newFixnum(result);
  }
};

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod(meta = true)
public static IRubyObject resolve(ThreadContext context, IRubyObject recv, IRubyObject name) {
  RubyEnumDescriptor rubyEnumDescriptorescriptor = (RubyEnumDescriptor) getDescriptor(context, recv);
  Descriptors.EnumDescriptor descriptor = rubyEnumDescriptorescriptor.getDescriptor();
  Descriptors.EnumValueDescriptor value = descriptor.findValueByName(name.asJavaString());
  if (value == null) return context.runtime.getNil();
  return context.runtime.newFixnum(value.getNumber());
}

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod
public IRubyObject hash(ThreadContext context) {
  int hashCode = this.storage.hashCode();
  return context.runtime.newFixnum(hashCode);
}

代码示例来源:origin: bazelbuild/bazel

private IRubyObject wrapField(ThreadContext context, Descriptors.FieldDescriptor fieldDescriptor, Object value) {
  if (value == null) {
    return context.runtime.getNil();
  }
  Ruby runtime = context.runtime;
  switch (fieldDescriptor.getType()) {
    case INT32:
    case INT64:
    case UINT32:
    case UINT64:
    case FLOAT:
    case DOUBLE:
    case BOOL:
    case BYTES:
    case STRING:
      return Utils.wrapPrimaryValue(context, fieldDescriptor.getType(), value);
    case MESSAGE:
      RubyClass typeClass = (RubyClass) ((RubyDescriptor) getDescriptorForField(context, fieldDescriptor)).msgclass(context);
      RubyMessage msg = (RubyMessage) typeClass.newInstance(context, Block.NULL_BLOCK);
      return msg.buildFrom(context, (DynamicMessage) value);
    case ENUM:
      Descriptors.EnumValueDescriptor enumValueDescriptor = (Descriptors.EnumValueDescriptor) value;
      if (enumValueDescriptor.getIndex() == -1) { // UNKNOWN ENUM VALUE
        return runtime.newFixnum(enumValueDescriptor.getNumber());
      }
      return runtime.newSymbol(enumValueDescriptor.getName());
    default:
      return runtime.newString(value.toString());
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

@JRubyMethod(required = 1)
public IRubyObject chmod(ThreadContext context, IRubyObject arg) {
  checkClosed(context);
  int mode = (int) arg.convertToInteger().getLongValue();
  if (!new File(path).exists()) {
    throw context.runtime.newErrnoENOENTError(path);
  }
  return context.runtime.newFixnum(context.runtime.getPosix().chmod(path, mode));
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
    int[] status = new int[1];
    Ruby runtime = context.runtime;
    int result = checkErrno(runtime, runtime.getPosix().waitpid(pid, status, 0));
    
    return runtime.newFixnum(result);
  }
};

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod(required = 4, optional = 1)
public IRubyObject map(ThreadContext context, IRubyObject[] args) {
  Ruby runtime = context.runtime;
  IRubyObject valueType = args[2];
  IRubyObject number = args[3];
  IRubyObject typeClass = args.length > 4 ? args[4] : context.runtime.getNil();
  keyField.setName(context, runtime.newString("key"));
  keyField.setLabel(context, RubySymbol.newSymbol(runtime, "optional"));
  keyField.setNumber(context, runtime.newFixnum(1));
  keyField.setType(context, keyType);
  mapentryDesc.addField(context, keyField);
  valueField.setName(context, runtime.newString("value"));
  valueField.setLabel(context, RubySymbol.newSymbol(runtime, "optional"));
  valueField.setNumber(context, runtime.newFixnum(2));
  valueField.setType(context, valueType);
  if (! typeClass.isNil()) valueField.setSubmsgName(context, typeClass);
  return runtime.getNil();

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod(name = {"length", "size"})
public IRubyObject length(ThreadContext context) {
  return context.runtime.newFixnum(this.storage.size());
}

代码示例来源:origin: bazelbuild/bazel

break;
case ENUM:
  IRubyObject defaultEnumLoc = context.runtime.newFixnum(0);
  return RubyEnum.lookup(context, typeClass, defaultEnumLoc);
default:
  return context.runtime.getNil();

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(required = 1)
public IRubyObject chmod(ThreadContext context, IRubyObject arg) {
  checkClosed(context);
  int mode = (int) arg.convertToInteger().getLongValue();
  if (!new File(path).exists()) {
    throw context.runtime.newErrnoENOENTError(path);
  }
  return context.runtime.newFixnum(context.runtime.getPosix().chmod(path, mode));
}

代码示例来源:origin: org.jruby/jruby-complete

public static IRubyObject getrlimit(Ruby runtime, IRubyObject arg) {
  if (!runtime.getPosix().isNative() || Platform.IS_WINDOWS) {
    runtime.getWarnings().warn("Process#getrlimit not supported on this platform");
    return runtime.newFixnum(Long.MAX_VALUE);
  }
  RLimit rlimit = runtime.getPosix().getrlimit(rlimitResourceType(runtime, arg));
  return runtime.newArray(runtime.newFixnum(rlimit.rlimCur()), runtime.newFixnum(rlimit.rlimMax()));
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod
public IRubyObject rewind(ThreadContext context) {
  Ruby runtime = context.runtime;
  // should invoke seek on realIo...
  realIo.callMethod(context, "seek",
      new IRubyObject[]{runtime.newFixnum(-internalPosition()), runtime.newFixnum(PosixShim.SEEK_CUR)});
  // ... and then reinitialize
  initialize(context, realIo);
  return getRuntime().getNil();
}

代码示例来源:origin: bazelbuild/bazel

@JRubyMethod
public IRubyObject hash(ThreadContext context) {
  try {
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    for (IRubyObject key : table.keySet()) {
      digest.update((byte) key.hashCode());
      digest.update((byte) table.get(key).hashCode());
    }
    return context.runtime.newString(new ByteList(digest.digest()));
  } catch (NoSuchAlgorithmException ignore) {
    return context.runtime.newFixnum(System.identityHashCode(table));
  }
}

代码示例来源:origin: org.jruby/jruby-complete

/** rb_ary_index
 *
 */
public IRubyObject index(ThreadContext context, IRubyObject obj) {
  Ruby runtime = context.runtime;
  for (int i = 0; i < realLength; i++) {
    if (equalInternal(context, eltOk(i), obj)) return runtime.newFixnum(i);
  }
  return runtime.getNil();
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(required = 1)
public IRubyObject chmod(ThreadContext context, IRubyObject arg) {
  checkClosed(context);
  int mode = (int) arg.convertToInteger().getLongValue();
  final String path = getPath();
  if ( ! new File(path).exists() ) {
    throw context.runtime.newErrnoENOENTError(path);
  }
  return context.runtime.newFixnum(context.runtime.getPosix().chmod(path, mode));
}

代码示例来源:origin: org.jruby/jruby-complete

public static IRubyObject egid(Ruby runtime) {
  if (Platform.IS_WINDOWS) {
    // MRI behavior on Windows
    return RubyFixnum.zero(runtime);
  }
  return runtime.newFixnum(checkErrno(runtime, runtime.getPosix().getegid()));
}

相关文章

Ruby类方法