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

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

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

RubyModule.defineAutoload介绍

[英]Define an autoload. ConstantMap holds UNDEF for the name as an autoload marker.
[中]定义自动加载。ConstantMap将名称的UNDEF作为自动加载标记保存。

代码示例

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

@JRubyMethod(required = 2, module = true, visibility = PRIVATE)
public static IRubyObject autoload(ThreadContext context, final IRubyObject recv, IRubyObject symbol, IRubyObject file) {
  final Ruby runtime = context.runtime;
  final String nonInternedName = symbol.asJavaString();
  if (!IdUtil.isValidConstantName(nonInternedName)) {
    throw runtime.newNameError("autoload must be constant name", nonInternedName);
  }
  final RubyString fileString =
    StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, file));
  if (fileString.isEmpty()) throw runtime.newArgumentError("empty file name");
  final String baseName = nonInternedName.intern(); // interned, OK for "fast" methods
  final RubyModule module = getModuleForAutoload(runtime, recv);
  IRubyObject existingValue = module.fetchConstant(baseName);
  if (existingValue != null && existingValue != RubyObject.UNDEF) return context.nil;
  module.defineAutoload(baseName, new RubyModule.AutoloadMethod() {
    public RubyString getFile() { return fileString; }
    public void load(final Ruby runtime) {
      final String file = getFile().asJavaString();
      if (runtime.getLoadService().autoloadRequire(file)) {
        // Do not finish autoloading by cyclic autoload
        module.finishAutoload(baseName);
      }
    }
  });
  return context.nil;
}

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

@JRubyMethod(required = 2, module = true, visibility = PRIVATE)
public static IRubyObject autoload(ThreadContext context, final IRubyObject recv, IRubyObject symbol, IRubyObject file) {
  final Ruby runtime = context.runtime;
  final String nonInternedName = symbol.asJavaString();
  if (!IdUtil.isValidConstantName(nonInternedName)) {
    throw runtime.newNameError("autoload must be constant name", nonInternedName);
  }
  final RubyString fileString =
    StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, file));
  if (fileString.isEmpty()) throw runtime.newArgumentError("empty file name");
  final String baseName = nonInternedName.intern(); // interned, OK for "fast" methods
  final RubyModule module = getModuleForAutoload(runtime, recv);
  IRubyObject existingValue = module.fetchConstant(baseName);
  if (existingValue != null && existingValue != RubyObject.UNDEF) return context.nil;
  module.defineAutoload(baseName, new RubyModule.AutoloadMethod() {
    public RubyString getFile() { return fileString; }
    public void load(final Ruby runtime) {
      final String file = getFile().asJavaString();
      if (runtime.getLoadService().autoloadRequire(file)) {
        // Do not finish autoloading by cyclic autoload
        module.finishAutoload(baseName);
      }
    }
  });
  return context.nil;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

if (existingValue != null && existingValue != RubyObject.UNDEF) return runtime.getNil();
module.defineAutoload(baseName, new IAutoloadMethod() {
  @Override
  public String file() {

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

if (existingValue != null && existingValue != RubyObject.UNDEF) return runtime.getNil();
module.defineAutoload(baseName, new IAutoloadMethod() {
  @Override
  public String file() {

相关文章

微信公众号

最新文章

更多

RubyModule类方法