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

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

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

Ruby.newString介绍

暂无

代码示例

代码示例来源: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: bazelbuild/bazel

@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());
}

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

@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));
  }
}

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

@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()));
}

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

@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();
}

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

@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();
}

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

@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));

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

@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]);
  }
}

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

@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") + ">");
}

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

@JRubyMethod
@Override
public RubyString name() {
  return getRuntime().newString(method.getName());
}

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

@JRubyMethod
public IRubyObject base_label(ThreadContext context) {
  if (baseLabel == null) baseLabel = context.runtime.newString(element.getMethodName());
  return baseLabel;
}

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

@JRubyMethod
public IRubyObject addr(ThreadContext context) {
  Ruby runtime = context.runtime;
  return runtime.newArray(
      runtime.newString("AF_UNIX"),
      runtime.newString(openFile.getPath()));
}

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

@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));
}

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

@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
}

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

@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
}

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

@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;
}

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

@Override
@JRubyMethod
public IRubyObject to_s() {
  return getRuntime().newString(toString());
}

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

@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;
}

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

@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);
}

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

@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);
}

相关文章

Ruby类方法