Refine search
@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 public IRubyObject inspect() { String cname = metaClass.getName(); StringBuilder sb = new StringBuilder("<"); sb.append(cname); sb.append(": "); sb.append(this.layoutInspect()); sb.append(">"); return getRuntime().newString(sb.toString()); }
@JRubyMethod public IRubyObject hash(ThreadContext context) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); for (RubyMap map : maps.values()) { digest.update((byte) map.hashCode()); } for (RubyRepeatedField repeatedField : repeatedFields.values()) { digest.update((byte) repeatedFields.hashCode()); } for (IRubyObject field : fields.values()) { digest.update((byte) field.hashCode()); } return context.runtime.newString(new ByteList(digest.digest())); } catch (NoSuchAlgorithmException ignore) { return context.runtime.newFixnum(System.identityHashCode(this)); } }
@JRubyMethod(meta = true) public static IRubyObject encode(ThreadContext context, IRubyObject recv, IRubyObject value) { RubyMessage message = (RubyMessage) value; return context.runtime.newString(new ByteList(message.build(context).toByteArray())); }
@JRubyMethod(name = "name=") public IRubyObject setName(ThreadContext context, IRubyObject name) { this.name = context.runtime.newString(name.asJavaString()); this.builder.setName(name.asJavaString()); return context.runtime.getNil(); }
@JRubyMethod(name = "name=") public IRubyObject setName(ThreadContext context, IRubyObject value) { String nameStr = value.asJavaString(); this.name = context.runtime.newString(nameStr); this.builder.setName(Utils.escapeIdentifier(nameStr)); return context.runtime.getNil(); }
@JRubyMethod(required = 4, optional = 1) public IRubyObject map(ThreadContext context, IRubyObject[] args) { Ruby runtime = context.runtime; keyField.setName(context, runtime.newString("key")); keyField.setLabel(context, RubySymbol.newSymbol(runtime, "optional")); keyField.setNumber(context, runtime.newFixnum(1)); valueField.setName(context, runtime.newString("value")); valueField.setLabel(context, RubySymbol.newSymbol(runtime, "optional")); valueField.setNumber(context, runtime.newFixnum(2));
@JRubyMethod(name = "method_missing", rest = true) public IRubyObject methodMissing(ThreadContext context, IRubyObject[] args) { if (args.length == 1) { RubyDescriptor rubyDescriptor = (RubyDescriptor) getDescriptor(context, metaClass); IRubyObject oneofDescriptor = rubyDescriptor.lookupOneof(context, args[0]); if (oneofDescriptor.isNil()) { if (!hasField(args[0])) { return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK); } return index(context, args[0]); } RubyOneofDescriptor rubyOneofDescriptor = (RubyOneofDescriptor) oneofDescriptor; Descriptors.FieldDescriptor fieldDescriptor = oneofCases.get(rubyOneofDescriptor.getOneofDescriptor()); if (fieldDescriptor == null) return context.runtime.getNil(); return context.runtime.newSymbol(fieldDescriptor.getName()); } else { // fieldName is RubySymbol RubyString field = args[0].asString(); RubyString equalSign = context.runtime.newString(Utils.EQUAL_SIGN); if (field.end_with_p(context, equalSign).isTrue()) { field.chomp_bang(context, equalSign); } if (!hasField(field)) { return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK); } return indexSet(context, field, args[1]); } }
@JRubyMethod public IRubyObject inspect(ThreadContext context) { if (inside) { // TODO: event-specific inspect output return context.runtime.newString("#<TracePoint:" + eventName + ">"); } return context.runtime.newString("#<TracePoint:" + (enabled ? "enabled" : "disabled") + ">"); }
@JRubyMethod @Override public RubyString name() { return getRuntime().newString(method.getName()); }
@JRubyMethod public IRubyObject base_label(ThreadContext context) { if (baseLabel == null) baseLabel = context.runtime.newString(element.getMethodName()); return baseLabel; }
@JRubyMethod public IRubyObject addr(ThreadContext context) { Ruby runtime = context.runtime; return runtime.newArray( runtime.newString("AF_UNIX"), runtime.newString(openFile.getPath())); }
@JRubyMethod public IRubyObject inspect(ThreadContext context) { String base = "#<Addrinfo: %s>"; String val; if (interfaceLink == true) { val = packet_inspect(); } else { val = inspect_sockaddr(context).toString(); } return context.runtime.newString(String.format(base, val)); }
@JRubyMethod(name = "[]", required = 1) public static IRubyObject aref(final ThreadContext context, final IRubyObject self, final IRubyObject idx) { final java.util.regex.Matcher matcher = unwrapJavaObject(self); if ( idx instanceof RubySymbol || idx instanceof RubyString ) { return context.runtime.newString( matcher.group(idx.toString()) ); } if ( idx instanceof RubyInteger ) { final int group = ((RubyInteger) idx).getIntValue(); return context.runtime.newString( matcher.group(group) ); } return to_a(context, self).aref(idx); // Range }
@JRubyMethod(name = "[]", required = 1) public static IRubyObject aref(final ThreadContext context, final IRubyObject self, final IRubyObject idx) { final java.util.regex.Matcher matcher = unwrapJavaObject(self); if ( idx instanceof RubySymbol || idx instanceof RubyString ) { return context.runtime.newString( matcher.group(idx.toString()) ); } if ( idx instanceof RubyInteger ) { final int group = ((RubyInteger) idx).getIntValue(); return context.runtime.newString( matcher.group(group) ); } return to_a(context, self).aref(idx); // Range }
@JRubyMethod(name = {"call", "[]"}, rest = true) public IRubyObject call(ThreadContext context, IRubyObject[] args) { if (disabled) { RubyKernel.raise(context, context.runtime.getThreadError(), new IRubyObject[]{context.runtime.newString("continuations can not be called from outside their scope")}, Block.NULL_BLOCK); } continuation.args = args; throw continuation; }
@Override @JRubyMethod public IRubyObject to_s() { return getRuntime().newString(toString()); }
@JRubyMethod(name = {"call", "[]"}, rest = true) public IRubyObject call(ThreadContext context, IRubyObject[] args) { if (disabled) { RubyKernel.raise(context, context.runtime.getThreadError(), new IRubyObject[]{context.runtime.newString("continuations can not be called from outside their scope")}, Block.NULL_BLOCK); } continuation.args = args; throw continuation; }
@JRubyMethod(meta = true) // for RubyGems' JRuby defaults public static IRubyObject classpath_launcher(ThreadContext context, IRubyObject recv) { final Ruby runtime = context.runtime; String launcher = runtime.getInstanceConfig().getEnvironment().get("RUBY"); if ( launcher == null ) launcher = ClasspathLauncher.jrubyCommand(runtime); return runtime.newString(launcher); }
@JRubyMethod(name = "extra_gem_paths", meta = true) // used from RGs' JRuby defaults public static IRubyObject extra_gem_paths(ThreadContext context, IRubyObject recv) { final Ruby runtime = context.runtime; final List<String> extraGemPaths = runtime.getInstanceConfig().getExtraGemPaths(); IRubyObject[] extra_gem_paths = new IRubyObject[extraGemPaths.size()]; int i = 0; for (String gemPath : extraGemPaths) { extra_gem_paths[i++] = runtime.newString(gemPath); } return RubyArray.newArrayNoCopy(runtime, extra_gem_paths); }