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

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

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

Ruby.newFixnum介绍

暂无

代码示例

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

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

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

  1. @JRubyMethod
  2. public IRubyObject each(ThreadContext context, Block block) {
  3. Ruby runtime = context.runtime;
  4. for (Descriptors.EnumValueDescriptor enumValueDescriptor : descriptor.getValues()) {
  5. block.yield(context, runtime.newArray(runtime.newSymbol(enumValueDescriptor.getName()),
  6. runtime.newFixnum(enumValueDescriptor.getNumber())));
  7. }
  8. return runtime.getNil();
  9. }

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

  1. switch (fieldType) {
  2. case INT32:
  3. return runtime.newFixnum((Integer) value);
  4. case INT64:
  5. return runtime.newFixnum((Long) value);
  6. case UINT32:
  7. return runtime.newFixnum(((Integer) value) & (-1l >>> 32));
  8. case UINT64:
  9. long ret = (Long) value;
  10. return ret >= 0 ? runtime.newFixnum(ret) :
  11. RubyBignum.newBignum(runtime, UINT64_COMPLEMENTARY.add(new BigInteger(ret + "")));
  12. case FLOAT:
  13. return runtime.getNil();

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

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

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

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

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

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

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

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

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

  1. private IRubyObject wrapField(ThreadContext context, Descriptors.FieldDescriptor fieldDescriptor, Object value) {
  2. if (value == null) {
  3. return context.runtime.getNil();
  4. }
  5. Ruby runtime = context.runtime;
  6. switch (fieldDescriptor.getType()) {
  7. case INT32:
  8. case INT64:
  9. case UINT32:
  10. case UINT64:
  11. case FLOAT:
  12. case DOUBLE:
  13. case BOOL:
  14. case BYTES:
  15. case STRING:
  16. return Utils.wrapPrimaryValue(context, fieldDescriptor.getType(), value);
  17. case MESSAGE:
  18. RubyClass typeClass = (RubyClass) ((RubyDescriptor) getDescriptorForField(context, fieldDescriptor)).msgclass(context);
  19. RubyMessage msg = (RubyMessage) typeClass.newInstance(context, Block.NULL_BLOCK);
  20. return msg.buildFrom(context, (DynamicMessage) value);
  21. case ENUM:
  22. Descriptors.EnumValueDescriptor enumValueDescriptor = (Descriptors.EnumValueDescriptor) value;
  23. if (enumValueDescriptor.getIndex() == -1) { // UNKNOWN ENUM VALUE
  24. return runtime.newFixnum(enumValueDescriptor.getNumber());
  25. }
  26. return runtime.newSymbol(enumValueDescriptor.getName());
  27. default:
  28. return runtime.newString(value.toString());
  29. }
  30. }

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

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

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

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

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

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

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

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

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

  1. break;
  2. case ENUM:
  3. IRubyObject defaultEnumLoc = context.runtime.newFixnum(0);
  4. return RubyEnum.lookup(context, typeClass, defaultEnumLoc);
  5. default:
  6. return context.runtime.getNil();

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

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

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

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

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

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

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

  1. @JRubyMethod
  2. public IRubyObject hash(ThreadContext context) {
  3. try {
  4. MessageDigest digest = MessageDigest.getInstance("SHA-256");
  5. for (IRubyObject key : table.keySet()) {
  6. digest.update((byte) key.hashCode());
  7. digest.update((byte) table.get(key).hashCode());
  8. }
  9. return context.runtime.newString(new ByteList(digest.digest()));
  10. } catch (NoSuchAlgorithmException ignore) {
  11. return context.runtime.newFixnum(System.identityHashCode(table));
  12. }
  13. }

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

  1. /** rb_ary_index
  2. *
  3. */
  4. public IRubyObject index(ThreadContext context, IRubyObject obj) {
  5. Ruby runtime = context.runtime;
  6. for (int i = 0; i < realLength; i++) {
  7. if (equalInternal(context, eltOk(i), obj)) return runtime.newFixnum(i);
  8. }
  9. return runtime.getNil();
  10. }

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

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

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

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

相关文章

Ruby类方法