本文整理了Java中org.jruby.runtime.Block
类的一些代码示例,展示了Block
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block
类的具体详情如下:
包路径:org.jruby.runtime.Block
类名称:Block
[英]Internal live representation of a block ({...} or do ... end).
[中]块({…})的内部实时表示或者做。。。(完)。
代码示例来源:origin: bazelbuild/bazel
@JRubyMethod
public IRubyObject build(ThreadContext context, Block block) {
RubyBuilder ctx = (RubyBuilder) cBuilder.newInstance(context, Block.NULL_BLOCK);
if (block.arity() == Arity.ONE_ARGUMENT) {
block.yield(context, ctx);
} else {
Binding binding = block.getBinding();
binding.setSelf(ctx);
block.yieldSpecific(context);
}
ctx.finalizeToPool(context, this);
buildFileDescriptor(context);
return context.runtime.getNil();
}
代码示例来源:origin: bazelbuild/bazel
@JRubyMethod
public IRubyObject oneof(ThreadContext context, IRubyObject name, Block block) {
RubyOneofDescriptor oneofdef = (RubyOneofDescriptor)
cOneofDescriptor.newInstance(context, Block.NULL_BLOCK);
RubyOneofBuilderContext ctx = (RubyOneofBuilderContext)
cOneofBuilderContext.newInstance(context, oneofdef, Block.NULL_BLOCK);
oneofdef.setName(context, name);
Binding binding = block.getBinding();
binding.setSelf(ctx);
block.yieldSpecific(context);
descriptor.addOneof(context, oneofdef);
return context.runtime.getNil();
}
代码示例来源:origin: org.jruby/jruby-complete
public static IRubyObject ensureYieldClose(ThreadContext context, IRubyObject port, Block block) {
if (block.isGiven()) {
try {
return block.yield(context, port);
} finally {
ioClose(context, port);
}
}
return port;
}
代码示例来源:origin: bazelbuild/bazel
@JRubyMethod
public IRubyObject each(ThreadContext context, Block block) {
for (Map.Entry<String, RubyFieldDescriptor> entry : fieldDefMap.entrySet()) {
block.yield(context, entry.getValue());
}
return context.runtime.getNil();
}
代码示例来源:origin: org.jruby/jruby-complete
public final IRubyObject call(ThreadContext context, IRubyObject[] args, IRubyObject self, Block passedBlock) {
assert args != null;
Block newBlock;
// bind to new self, if given
if (self == null) {
newBlock = block;
} else {
newBlock = block.cloneBlockAndFrame();
newBlock.getBinding().setSelf(self);
}
return newBlock.call(context, args, passedBlock);
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod(name = {"module_exec", "class_exec"},
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
public IRubyObject module_exec(ThreadContext context, Block block) {
if (block.isGiven()) {
return yieldUnder(context, this, IRubyObject.NULL_ARRAY, block.cloneBlockAndFrame(), EvalType.MODULE_EVAL);
} else {
throw context.runtime.newLocalJumpErrorNoBlock();
}
}
代码示例来源:origin: org.jruby/jruby-complete
@Override
public IRubyObject size(IRubyObject[] args) {
return block.call(context, args);
}
};
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod
public IRubyObject each_char(final ThreadContext context, final Block block) {
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each_char");
IRubyObject c;
while (!(c = getc(context)).isNil()) {
block.yieldSpecific(context, c);
}
return this;
}
代码示例来源:origin: org.jruby/jruby-complete
/** rb_ary_cycle
*
*/
@JRubyMethod(name = "cycle")
public IRubyObject cycle(ThreadContext context, Block block) {
if (!block.isGiven()) return enumeratorizeWithSize(context, this, "cycle", cycleSizeFn(context));
return cycleCommon(context, -1, block);
}
代码示例来源:origin: org.jruby/jruby-complete
private void yieldRefineBlock(ThreadContext context, RubyModule refinement, Block block) {
block.setEvalType(EvalType.MODULE_EVAL);
block.getBinding().setSelf(refinement);
block.yieldSpecific(context);
}
代码示例来源:origin: org.jruby/jruby-complete
private Block setupBlock(Block block, EvalType evalType) {
if (block.getProcObject() == null) {
// FIXME: This is an ugly hack to resolve JRUBY-1381; I'm not proud of it
block = block.cloneBlockForEval(this, evalType);
} else {
block = block.deepCloneBlockForEval(this, evalType);
}
block.getBinding().setVisibility(PUBLIC);
return block;
}
代码示例来源:origin: org.jruby/jruby-complete
private DynamicMethod createProcMethod(Ruby runtime, String name, Visibility visibility, Block block) {
block = block.cloneBlockAndFrame();
block.getBinding().getFrame().setKlazz(this);
block.getBinding().getFrame().setName(name);
block.getBinding().setMethod(name);
// a normal block passed to define_method changes to do arity checking; make it a lambda
RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block);
// various instructions can tell this scope is not an ordinary block but a block representing
// a method definition.
block.getBody().getStaticScope().makeArgumentScope();
return new ProcMethod(this, proc, visibility, name);
}
代码示例来源:origin: bazelbuild/bazel
@JRubyMethod
public IRubyObject each(ThreadContext context, Block block) {
for (IRubyObject key : table.keySet()) {
block.yieldSpecific(context, key, table.get(key));
}
return context.runtime.getNil();
}
代码示例来源:origin: org.jruby/jruby-complete
public Block cloneBlockForEval(IRubyObject self, EvalType evalType) {
Block block = cloneBlock();
block.getBinding().setSelf(self);
block.getBinding().getFrame().setSelf(self);
block.setEvalType(evalType);
return block;
}
代码示例来源:origin: org.jruby/jruby-complete
public Block cloneBlock() {
Block newBlock = new Block(body, binding);
newBlock.type = type;
newBlock.escapeBlock = this;
return newBlock;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
private Block setupBlock(Block block) {
// FIXME: This is an ugly hack to resolve JRUBY-1381; I'm not proud of it
block = block.cloneBlock();
block.getBinding().setSelf(this);
block.getBinding().getFrame().setSelf(this);
return block;
}
代码示例来源:origin: org.jruby/jruby-complete
public Block deepCloneBlockForEval(IRubyObject self, EvalType evalType) {
Block block = cloneBlockAndBinding();
block.getBinding().setSelf(self);
block.getBinding().getFrame().setSelf(self);
block.setEvalType(evalType);
return block;
}
代码示例来源:origin: org.jruby/jruby-complete
@Interp @JIT
public static IRubyObject updateBlockState(Block block, IRubyObject self) {
// SSS FIXME: Why is self null in non-binding-eval contexts?
if (self == null || block.getEvalType() == EvalType.BINDING_EVAL) {
// Update self to the binding's self
self = useBindingSelf(block.getBinding());
}
// Clear block's eval type
block.setEvalType(EvalType.NONE);
// Return self in case it has been updated
return self;
}
代码示例来源:origin: org.jruby/jruby-complete
@Override
protected IRubyObject callDirect(ThreadContext context, Block block, IRubyObject[] args, Block blockArg) {
InterpreterContext ic = ensureInstrsReady(); // so we get debugging output
return Interpreter.INTERPRET_BLOCK(context, block, null, ic, args, block.getBinding().getMethod(), blockArg);
}
代码示例来源:origin: org.jruby/jruby-complete
private static DynamicScope getNewBlockScope(Block block, boolean pushNewDynScope, boolean reuseParentDynScope) {
DynamicScope newScope = block.getBinding().getDynamicScope();
if (pushNewDynScope) return block.allocScope(newScope);
// Reuse! We can avoid the push only if surrounding vars aren't referenced!
if (reuseParentDynScope) return newScope;
// No change
return null;
}
内容来源于网络,如有侵权,请联系作者删除!