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

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

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

Ruby.newSymbol介绍

暂无

代码示例

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

  1. private static IRubyObject fieldTypeToRuby(ThreadContext context, String typeName) {
  2. return context.runtime.newSymbol(typeName.replace("TYPE_", "").toLowerCase());
  3. }

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

  1. @JRubyMethod(name = "label=")
  2. public IRubyObject setLabel(ThreadContext context, IRubyObject value) {
  3. String labelName = value.asJavaString();
  4. this.label = context.runtime.newSymbol(labelName.toLowerCase());
  5. this.builder.setLabel(
  6. DescriptorProtos.FieldDescriptorProto.Label.valueOf("LABEL_" + labelName.toUpperCase()));
  7. return context.runtime.getNil();
  8. }

代码示例来源: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. @JRubyMethod(meta = true)
  2. public static IRubyObject lookup(ThreadContext context, IRubyObject recv, IRubyObject number) {
  3. RubyEnumDescriptor rubyEnumDescriptorescriptor = (RubyEnumDescriptor) getDescriptor(context, recv);
  4. Descriptors.EnumDescriptor descriptor = rubyEnumDescriptorescriptor.getDescriptor();
  5. Descriptors.EnumValueDescriptor value = descriptor.findValueByNumber(RubyNumeric.num2int(number));
  6. if (value == null) return context.runtime.getNil();
  7. return context.runtime.newSymbol(value.getName());
  8. }

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

  1. @JRubyMethod(name = "decode_json", meta = true)
  2. public static IRubyObject decodeJson(ThreadContext context, IRubyObject recv, IRubyObject json) {
  3. Ruby runtime = context.runtime;
  4. RubyMessage ret = (RubyMessage) ((RubyClass) recv).newInstance(context, Block.NULL_BLOCK);
  5. RubyModule jsonModule = runtime.getClassFromPath("JSON");
  6. RubyHash opts = RubyHash.newHash(runtime);
  7. opts.fastASet(runtime.newSymbol("symbolize_names"), runtime.getTrue());
  8. IRubyObject[] args = new IRubyObject[] { Helpers.invoke(context, jsonModule, "parse", json, opts) };
  9. ret.initialize(context, args);
  10. return ret;
  11. }

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

  1. Descriptors.EnumValueDescriptor val =
  2. enumDescriptor.findValueByNumberCreatingIfUnknown(RubyNumeric.num2int(value));
  3. if (val.getIndex() != -1) value = context.runtime.newSymbol(val.getName());

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

  1. @JRubyMethod(name = "method_missing", rest = true)
  2. public IRubyObject methodMissing(ThreadContext context, IRubyObject[] args) {
  3. if (args.length == 1) {
  4. RubyDescriptor rubyDescriptor = (RubyDescriptor) getDescriptor(context, metaClass);
  5. IRubyObject oneofDescriptor = rubyDescriptor.lookupOneof(context, args[0]);
  6. if (oneofDescriptor.isNil()) {
  7. if (!hasField(args[0])) {
  8. return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK);
  9. }
  10. return index(context, args[0]);
  11. }
  12. RubyOneofDescriptor rubyOneofDescriptor = (RubyOneofDescriptor) oneofDescriptor;
  13. Descriptors.FieldDescriptor fieldDescriptor =
  14. oneofCases.get(rubyOneofDescriptor.getOneofDescriptor());
  15. if (fieldDescriptor == null)
  16. return context.runtime.getNil();
  17. return context.runtime.newSymbol(fieldDescriptor.getName());
  18. } else {
  19. // fieldName is RubySymbol
  20. RubyString field = args[0].asString();
  21. RubyString equalSign = context.runtime.newString(Utils.EQUAL_SIGN);
  22. if (field.end_with_p(context, equalSign).isTrue()) {
  23. field.chomp_bang(context, equalSign);
  24. }
  25. if (!hasField(field)) {
  26. return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK);
  27. }
  28. return indexSet(context, field, args[1]);
  29. }
  30. }

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

  1. msgdefAddField(context, "repeated", name, runtime.newSymbol("message"), number, mapentryDescName);
  2. return runtime.getNil();

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

  1. @JRubyMethod(name = {"to_h", "to_hash"})
  2. public IRubyObject toHash(ThreadContext context) {
  3. Ruby runtime = context.runtime;
  4. RubyHash ret = RubyHash.newHash(runtime);
  5. for (Descriptors.FieldDescriptor fdef : this.descriptor.getFields()) {
  6. IRubyObject value = getField(context, fdef);
  7. if (!value.isNil()) {
  8. if (fdef.isRepeated() && !fdef.isMapField()) {
  9. if (fdef.getType() != Descriptors.FieldDescriptor.Type.MESSAGE) {
  10. value = Helpers.invoke(context, value, "to_a");
  11. } else {
  12. RubyArray ary = value.convertToArray();
  13. for (int i = 0; i < ary.size(); i++) {
  14. IRubyObject submsg = Helpers.invoke(context, ary.eltInternal(i), "to_h");
  15. ary.eltInternalSet(i, submsg);
  16. }
  17. value = ary.to_ary();
  18. }
  19. } else if (value.respondsTo("to_h")) {
  20. value = Helpers.invoke(context, value, "to_h");
  21. } else if (value.respondsTo("to_a")) {
  22. value = Helpers.invoke(context, value, "to_a");
  23. }
  24. }
  25. ret.fastASet(runtime.newSymbol(fdef.getName()), value);
  26. }
  27. return ret;
  28. }

代码示例来源:origin: asciidoctor/asciidoctorj

  1. private static void handleContentModelAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) {
  2. Ruby rubyRuntime = rubyClass.getRuntime();
  3. if (processor.isAnnotationPresent(ContentModel.class)) {
  4. ContentModel contentModel = processor.getAnnotation(ContentModel.class);
  5. rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
  6. rubyRuntime.newSymbol("content_model"),
  7. rubyRuntime.newSymbol(contentModel.value().substring(1))
  8. });
  9. }
  10. }

代码示例来源:origin: asciidoctor/asciidoctorj

  1. private static void handleLocationAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) {
  2. Ruby rubyRuntime = rubyClass.getRuntime();
  3. if (processor.isAnnotationPresent(Location.class)) {
  4. Location location = processor.getAnnotation(Location.class);
  5. rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{
  6. rubyRuntime.newSymbol("location"),
  7. rubyRuntime.newSymbol(location.value().optionValue().substring(1))
  8. });
  9. }
  10. }

代码示例来源:origin: asciidoctor/asciidoctorj

  1. @Override
  2. public void register(IRubyObject registry) {
  3. registry.callMethod(rubyRuntime.getCurrentContext(), "block", new IRubyObject[]{rubyClass, rubyRuntime.newSymbol(blockName)});
  4. }
  5. });

代码示例来源:origin: asciidoctor/asciidoctorj

  1. @Override
  2. public void register(IRubyObject registry) {
  3. registry.callMethod(rubyRuntime.getCurrentContext(), "block_macro", new IRubyObject[]{rubyClass, rubyRuntime.newSymbol(blockName)});
  4. }
  5. });

代码示例来源:origin: asciidoctor/asciidoctorj

  1. @Override
  2. public void register(IRubyObject registry) {
  3. registry.callMethod(rubyRuntime.getCurrentContext(), "inline_macro", new IRubyObject[]{rubyClass, rubyRuntime.newSymbol(name)});
  4. }
  5. });

代码示例来源:origin: asciidoctor/asciidoctorj

  1. @Override
  2. public void register(IRubyObject registry) {
  3. registry.callMethod(rubyRuntime.getCurrentContext(), "block", new IRubyObject[]{rubyClass, rubyRuntime.newSymbol(blockProcessor.getName())});
  4. }
  5. });

代码示例来源:origin: asciidoctor/asciidoctorj

  1. @Override
  2. public void register(IRubyObject registry) {
  3. registry.callMethod(rubyRuntime.getCurrentContext(), "inline_macro", new IRubyObject[]{rubyClass, rubyRuntime.newSymbol(AbstractProcessorProxy.getName(inlineMacroProcessor))});
  4. }
  5. });

代码示例来源:origin: asciidoctor/asciidoctorj

  1. @Override
  2. public void register(IRubyObject registry) {
  3. registry.callMethod(rubyRuntime.getCurrentContext(), "block_macro", new IRubyObject[]{rubyClass, rubyRuntime.newSymbol(AbstractProcessorProxy.getName(blockMacroProcessor))});
  4. }
  5. });

代码示例来源:origin: asciidoctor/asciidoctorj

  1. @Override
  2. public void register(IRubyObject registry) {
  3. registry.callMethod(rubyRuntime.getCurrentContext(), "block", new IRubyObject[]{rubyRuntime.newString(blockProcessor), rubyRuntime.newSymbol(blockName)});
  4. }
  5. });

代码示例来源:origin: asciidoctor/asciidoctorj

  1. private Cursor getSourceLocation(IRubyObject msg) {
  2. if (getRuntime().getHash().equals(msg.getType())) {
  3. final RubyHash hash = (RubyHash) msg;
  4. final Object sourceLocation = hash.get(getRuntime().newSymbol(LOG_PROPERTY_SOURCE_LOCATION));
  5. return new CursorImpl((IRubyObject) sourceLocation);
  6. }
  7. return null;
  8. }
  9. }

相关文章

Ruby类方法