org.jruby.RubyModule.constantDefined()方法的使用及代码示例

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

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

RubyModule.constantDefined介绍

暂无

代码示例

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

@JRubyMethod(name = "const_defined?", required = 1, optional = 1)
public RubyBoolean const_defined_p19(ThreadContext context, IRubyObject[] args) {
  Ruby runtime = context.runtime;
  boolean inherit = args.length == 1 || (!args[1].isNil() && args[1].isTrue());
  if (args[0] instanceof RubySymbol) return constantDefined(runtime, ((RubySymbol) args[0]), inherit);
  RubyString fullName = args[0].convertToString();
  IRubyObject value = ByteListHelper.split(fullName.getByteList(), CommonByteLists.COLON_COLON, (index, segment, module) -> {
    if (index == 0) {
      if (segment.realSize() == 0) return runtime.getObject();  // '::Foo...'
      module = this;
    }
    String id = RubySymbol.newConstantSymbol(runtime, fullName, segment).idString();
    IRubyObject obj = ((RubyModule) module).getConstantNoConstMissing(id, inherit, inherit);
    if (obj == null) return null;
    if (!(obj instanceof RubyModule)) throw runtime.newTypeError(segment + " does not refer to class/module");
    return obj;
  }, (index, segment, module) -> {
    if (module == null) module = this; // Bare 'Foo'
    String id = RubySymbol.newConstantSymbol(runtime, fullName, segment).idString();
    return ((RubyModule) module).getConstantSkipAutoload(id, inherit, inherit);
  });
  return runtime.newBoolean(value != null);
}

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

@JRubyMethod(name = "const_defined?", required = 1, optional = 1)
public RubyBoolean const_defined_p19(ThreadContext context, IRubyObject[] args) {
  Ruby runtime = context.runtime;
  boolean inherit = args.length == 1 || (!args[1].isNil() && args[1].isTrue());
  if (args[0] instanceof RubySymbol) return constantDefined(runtime, ((RubySymbol) args[0]), inherit);
  RubyString fullName = args[0].convertToString();
  IRubyObject value = ByteListHelper.split(fullName.getByteList(), CommonByteLists.COLON_COLON, (index, segment, module) -> {
    if (index == 0) {
      if (segment.realSize() == 0) return runtime.getObject();  // '::Foo...'
      module = this;
    }
    String id = RubySymbol.newConstantSymbol(runtime, fullName, segment).idString();
    IRubyObject obj = ((RubyModule) module).getConstantNoConstMissing(id, inherit, inherit);
    if (obj == null) return null;
    if (!(obj instanceof RubyModule)) throw runtime.newTypeError(segment + " does not refer to class/module");
    return obj;
  }, (index, segment, module) -> {
    if (module == null) module = this; // Bare 'Foo'
    String id = RubySymbol.newConstantSymbol(runtime, fullName, segment).idString();
    return ((RubyModule) module).getConstantSkipAutoload(id, inherit, inherit);
  });
  return runtime.newBoolean(value != null);
}

相关文章

微信公众号

最新文章

更多

RubyModule类方法