Refine search
@JRubyMethod public IRubyObject length(ThreadContext context) { return context.runtime.newFixnum(this.table.size()); }
@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(); }
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();
@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)); }
@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()); }
@JRubyMethod public IRubyObject hash(ThreadContext context) { int hashCode = this.storage.hashCode(); return context.runtime.newFixnum(hashCode); }
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()); } }
@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)); }
@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();
@JRubyMethod(name = {"length", "size"}) public IRubyObject length(ThreadContext context) { return context.runtime.newFixnum(this.storage.size()); }
@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)); }
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())); }
@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(); }
@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)); } }
@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)); }