本文整理了Java中org.jruby.RubyModule.constantDefined
方法的一些代码示例,展示了RubyModule.constantDefined
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RubyModule.constantDefined
方法的具体详情如下:
包路径:org.jruby.RubyModule
类名称: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);
}
内容来源于网络,如有侵权,请联系作者删除!