@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(); }
@JRubyMethod public IRubyObject each(ThreadContext context, Block block) { for (IRubyObject key : table.keySet()) { block.yieldSpecific(context, key, table.get(key)); } return context.runtime.getNil(); }
@JRubyMethod(name = "encode_json", meta = true) public static IRubyObject encodeJson(ThreadContext context, IRubyObject recv, IRubyObject msgRb) { RubyMessage message = (RubyMessage) msgRb; return Helpers.invoke(context, message.toHash(context), "to_json"); }
public static IRubyObject callZSuper(Ruby runtime, ThreadContext context, Block block, IRubyObject self) { // Has the method that is calling super received a block argument if (!block.isGiven()) block = context.getCurrentFrame().getBlock(); return Helpers.invokeSuper(context, self, context.getCurrentScope().getArgValues(), block); }
@JRubyMethod(name = "method_missing", rest = true) public IRubyObject methodMissing(ThreadContext context, IRubyObject[] args) { if (args.length == 1) { RubyDescriptor rubyDescriptor = (RubyDescriptor) getDescriptor(context, metaClass); IRubyObject oneofDescriptor = rubyDescriptor.lookupOneof(context, args[0]); if (oneofDescriptor.isNil()) { if (!hasField(args[0])) { return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK); } return index(context, args[0]); } RubyOneofDescriptor rubyOneofDescriptor = (RubyOneofDescriptor) oneofDescriptor; Descriptors.FieldDescriptor fieldDescriptor = oneofCases.get(rubyOneofDescriptor.getOneofDescriptor()); if (fieldDescriptor == null) return context.runtime.getNil(); return context.runtime.newSymbol(fieldDescriptor.getName()); } else { // fieldName is RubySymbol RubyString field = args[0].asString(); RubyString equalSign = context.runtime.newString(Utils.EQUAL_SIGN); if (field.end_with_p(context, equalSign).isTrue()) { field.chomp_bang(context, equalSign); } if (!hasField(field)) { return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK); } return indexSet(context, field, args[1]); } }
@JRubyMethod(name = {"to_h", "to_hash"}) public IRubyObject toHash(ThreadContext context) { Ruby runtime = context.runtime; RubyHash ret = RubyHash.newHash(runtime); for (Descriptors.FieldDescriptor fdef : this.descriptor.getFields()) { IRubyObject value = getField(context, fdef); if (!value.isNil()) { if (fdef.isRepeated() && !fdef.isMapField()) { if (fdef.getType() != Descriptors.FieldDescriptor.Type.MESSAGE) { value = Helpers.invoke(context, value, "to_a"); } else { RubyArray ary = value.convertToArray(); for (int i = 0; i < ary.size(); i++) { IRubyObject submsg = Helpers.invoke(context, ary.eltInternal(i), "to_h"); ary.eltInternalSet(i, submsg); } value = ary.to_ary(); } } else if (value.respondsTo("to_h")) { value = Helpers.invoke(context, value, "to_h"); } else if (value.respondsTo("to_a")) { value = Helpers.invoke(context, value, "to_a"); } } ret.fastASet(runtime.newSymbol(fdef.getName()), value); } return ret; }
public Block cloneBlockForEval(IRubyObject self, EvalType evalType) { Block block = cloneBlock(); block.getBinding().setSelf(self); block.getBinding().getFrame().setSelf(self); block.setEvalType(evalType); return block; }
@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(); }
public Block deepCloneBlockForEval(IRubyObject self, EvalType evalType) { Block block = cloneBlockAndBinding(); block.getBinding().setSelf(self); block.getBinding().getFrame().setSelf(self); block.setEvalType(evalType); return block; }
@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(); }
public Frame preYieldSpecificBlock(Binding binding, StaticScope scope) { Frame lastFrame = preYieldNoScope(binding); // new scope for this invocation of the block, based on parent scope pushScope(DynamicScope.newDynamicScope(scope, binding.getDynamicScope())); return lastFrame; }
public static Block newCallClosure(IRubyObject self, RubyModule imClass, Signature signature, BlockCallback callback, ThreadContext context) { Binding binding = context.currentBinding(self, Visibility.PUBLIC); BlockBody body = new CallBlock(signature, callback, context); return new Block(body, binding); }
public static Block newCallClosure(IRubyObject self, RubyModule imClass, Signature signature, BlockCallback callback, ThreadContext context) { Binding binding = context.currentBinding(self, Visibility.PUBLIC); BlockBody body = new CallBlock19(signature, callback, context); return new Block(body, binding); }
@JRubyMethod(name = "add_enum") public IRubyObject addEnum(ThreadContext context, IRubyObject name, Block block) { RubyEnumDescriptor enumDef = (RubyEnumDescriptor) cEnumDescriptor.newInstance(context, Block.NULL_BLOCK); IRubyObject ctx = cEnumBuilderContext.newInstance(context, enumDef, Block.NULL_BLOCK); enumDef.setName(context, name); if (block.isGiven()) { if (block.arity() == Arity.ONE_ARGUMENT) { block.yield(context, ctx); } else { Binding binding = block.getBinding(); binding.setSelf(ctx); block.yieldSpecific(context); } } this.pendingList.add(enumDef); return context.runtime.getNil(); }
public static IRubyObject callZSuper(Ruby runtime, ThreadContext context, Block block, IRubyObject self) { // Has the method that is calling super received a block argument if (!block.isGiven()) block = context.getCurrentFrame().getBlock(); return Helpers.invokeSuper(context, self, context.getCurrentScope().getArgValues(), block); }
@JRubyMethod public IRubyObject each(ThreadContext context, Block block) { Ruby runtime = context.runtime; for (Descriptors.EnumValueDescriptor enumValueDescriptor : descriptor.getValues()) { block.yield(context, runtime.newArray(runtime.newSymbol(enumValueDescriptor.getName()), runtime.newFixnum(enumValueDescriptor.getNumber()))); } return runtime.getNil(); }
@JRubyMethod public IRubyObject each(ThreadContext context, Block block) { for (RubyFieldDescriptor field : fields) { block.yieldSpecific(context, field); } return context.runtime.getNil(); }
@JRubyMethod(name = "decode_json", meta = true) public static IRubyObject decodeJson(ThreadContext context, IRubyObject recv, IRubyObject json) { Ruby runtime = context.runtime; RubyMessage ret = (RubyMessage) ((RubyClass) recv).newInstance(context, Block.NULL_BLOCK); RubyModule jsonModule = runtime.getClassFromPath("JSON"); RubyHash opts = RubyHash.newHash(runtime); opts.fastASet(runtime.newSymbol("symbolize_names"), runtime.getTrue()); IRubyObject[] args = new IRubyObject[] { Helpers.invoke(context, jsonModule, "parse", json, opts) }; ret.initialize(context, args); return ret; }
@JRubyMethod(name = "add_message") public IRubyObject addMessage(ThreadContext context, IRubyObject name, Block block) { RubyDescriptor msgdef = (RubyDescriptor) cDescriptor.newInstance(context, Block.NULL_BLOCK); IRubyObject ctx = cMessageBuilderContext.newInstance(context, msgdef, this, Block.NULL_BLOCK); msgdef.setName(context, name); if (block.isGiven()) { if (block.arity() == Arity.ONE_ARGUMENT) { block.yield(context, ctx); } else { Binding binding = block.getBinding(); binding.setSelf(ctx); block.yieldSpecific(context); } } this.pendingList.add(msgdef); return context.runtime.getNil(); }
@JRubyMethod(name = "each_oneof") public IRubyObject eachOneof(ThreadContext context, Block block) { for (RubyOneofDescriptor oneofDescriptor : oneofDefs.values()) { block.yieldSpecific(context, oneofDescriptor); } return context.runtime.getNil(); }