Example #1
0
  @Override
  public IRubyObject yield(
      ThreadContext context,
      IRubyObject[] args,
      IRubyObject self,
      RubyModule klass,
      Binding binding,
      Block.Type type,
      Block block) {
    if (klass == null) {
      self = prepareSelf(binding);
    }

    Visibility oldVis = binding.getFrame().getVisibility();
    Frame lastFrame = pre(context, klass, binding);
    Ruby runtime = context.runtime;

    try {
      if (!noargblock) {
        IRubyObject[] preppedArgs = RubyProc.prepareArgs(context, type, arity, args);
        RubyArray argArray = context.runtime.newArrayNoCopyLight(preppedArgs);
        IRubyObject value = assigner.convertIfAlreadyArray(runtime, argArray);

        assigner.assignArray(runtime, context, self, value, block);
      }

      // This while loop is for restarting the block call in case a 'redo' fires.
      return evalBlockBody(context, binding, self);
    } catch (JumpException.FlowControlException jump) {
      return Helpers.handleBlockJump(context, jump, type);
    } finally {
      post(context, binding, oldVis, lastFrame);
    }
  }
Example #2
0
  @Override
  public IRubyObject yieldSpecific(
      ThreadContext context,
      IRubyObject arg0,
      IRubyObject arg1,
      IRubyObject arg2,
      Binding binding,
      Block.Type type) {
    Visibility oldVis = binding.getFrame().getVisibility();
    Frame lastFrame = pre(context, null, binding);
    IRubyObject self = prepareSelf(binding);

    try {
      if (!noargblock) {
        assigner.assign(context.runtime, context, self, arg0, arg1, arg2, Block.NULL_BLOCK);
      }

      // This while loop is for restarting the block call in case a 'redo' fires.
      return evalBlockBody(context, binding, self);
    } catch (JumpException.FlowControlException jump) {
      return Helpers.handleBlockJump(context, jump, type);
    } finally {
      post(context, binding, oldVis, lastFrame);
    }
  }
Example #3
0
  @Override
  public IRubyObject yield(
      ThreadContext context, IRubyObject value, Binding binding, Block.Type type, Block block) {
    IRubyObject self = prepareSelf(binding);
    Visibility oldVis = binding.getFrame().getVisibility();
    Frame lastFrame = pre(context, null, binding);

    try {
      if (!noargblock) {
        assigner.assignArray(
            context.runtime, context, self, assigner.convertToArray(context.runtime, value), block);
      }

      return evalBlockBody(context, binding, self);
    } catch (JumpException.FlowControlException jump) {
      return Helpers.handleBlockJump(context, jump, type);
    } finally {
      post(context, binding, oldVis, lastFrame);
    }
  }