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

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

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

RubyModule.createNewRefinedModule介绍

暂无

代码示例

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

@JRubyMethod(name = "refine", required = 1, reads = SCOPE)
public IRubyObject refine(ThreadContext context, IRubyObject target, Block block) {
  if (!block.isGiven()) throw context.runtime.newArgumentError("no block given");
  if (block.isEscaped()) throw context.runtime.newArgumentError("can't pass a Proc as a block to Module#refine");
  if (!(target instanceof RubyModule)) throw context.runtime.newTypeError("wrong argument type " + target.getType() + "(expected Class or Module)");
  if (refinements == Collections.EMPTY_MAP) refinements = new IdentityHashMap<>();
  if (activatedRefinements == Collections.EMPTY_MAP) activatedRefinements = new IdentityHashMap<>();
  RubyModule moduleToRefine = (RubyModule) target;
  RubyModule refinement = refinements.get(moduleToRefine);
  if (refinement == null) {
    refinement = createNewRefinedModule(context, moduleToRefine);
    // Add it to the activated chain of other refinements already added to this class we are refining
    addActivatedRefinement(context, moduleToRefine, refinement);
  }
  // Executes the block supplied with the defined method definitions using the refinment as it's module.
  yieldRefineBlock(context, refinement, block);
  return refinement;
}

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

@JRubyMethod(name = "refine", required = 1, reads = SCOPE)
public IRubyObject refine(ThreadContext context, IRubyObject target, Block block) {
  if (!block.isGiven()) throw context.runtime.newArgumentError("no block given");
  if (block.isEscaped()) throw context.runtime.newArgumentError("can't pass a Proc as a block to Module#refine");
  if (!(target instanceof RubyModule)) throw context.runtime.newTypeError("wrong argument type " + target.getType() + "(expected Class or Module)");
  if (refinements == Collections.EMPTY_MAP) refinements = new IdentityHashMap<>();
  if (activatedRefinements == Collections.EMPTY_MAP) activatedRefinements = new IdentityHashMap<>();
  RubyModule moduleToRefine = (RubyModule) target;
  RubyModule refinement = refinements.get(moduleToRefine);
  if (refinement == null) {
    refinement = createNewRefinedModule(context, moduleToRefine);
    // Add it to the activated chain of other refinements already added to this class we are refining
    addActivatedRefinement(context, moduleToRefine, refinement);
  }
  // Executes the block supplied with the defined method definitions using the refinment as it's module.
  yieldRefineBlock(context, refinement, block);
  return refinement;
}

相关文章

微信公众号

最新文章

更多

RubyModule类方法