{"record":{"id":"5f1a4491d2f8334b","repo":"krahets/hello-algo","slug":"error-5f1a44","errorCode":null,"errorMessage":"キューは空です","messagePattern":"キューは空です","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"ja/codes/ruby/chapter_stack_and_queue/array_queue.rb","lineNumber":52,"sourceCode":"    # 剰余演算により、rear が配列末尾を越えた後に先頭へ戻るようにする\n    rear = (@front + size) % capacity\n    # num をキュー末尾に追加\n    @nums[rear] = num\n    @size += 1\n  end\n\n  ### デキュー ###\n  def pop\n    num = peek\n    # 先頭ポインタを1つ後ろへ進め、末尾を越えたら配列先頭に戻す\n    @front = (@front + 1) % capacity\n    @size -= 1\n    num\n  end\n\n  ### 先頭要素にアクセス ###\n  def peek\n    raise IndexError, 'キューは空です' if is_empty?\n\n    @nums[@front]\n  end\n\n  ### 表示用のリストを返す ###\n  def to_array\n    res = Array.new(size, 0)\n    j = @front\n\n    for i in 0...size\n      res[i] = @nums[j % capacity]\n      j += 1\n    end\n\n    res\n  end\nend\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ja/codes/ruby/chapter_stack_and_queue/array_queue.rb#L34-L70","documentation":"Raised by ArrayQueue#peek (ja/codes/ruby/chapter_stack_and_queue/array_queue.rb:52) when the queue is empty. It returns @nums[@front], invalid when size == 0, so the guard blocks the read. pop calls peek first, so dequeue on an empty queue surfaces this too. Message: \"キューは空です\" (Queue is empty). Japanese mirror of error 540.","triggerScenarios":"Calling queue.peek or queue.pop when queue.size == 0 — before the first push, or after the front pointer has advanced past every element.","commonSituations":"Draining a circular queue past empty in a producer/consumer loop; consumer outrunning the producer; test code popping more than it pushed.","solutions":["Check queue.is_empty? before peek/pop.","Keep enqueued and dequeued counts balanced.","Rescue IndexError around dequeue and treat empty as idle."],"exampleFix":"# before\nqueue = ArrayQueue.new(10)\nqueue.pop # raises IndexError, \"キューは空です\"\n\n# after\nqueue.pop unless queue.is_empty?","handlingStrategy":"validation","validationCode":"queue.pop unless queue.is_empty?","typeGuard":"def queue_nonempty?(q); q.respond_to?(:is_empty?) && !q.is_empty?; end","tryCatchPattern":"begin\n  queue.pop\nrescue IndexError\n  nil\nend","preventionTips":["Check is_empty? before peek/pop.","Balance enqueue/dequeue counts.","Make emptiness the consumer loop's idle state."],"tags":["ruby","queue","circular-array","precondition","indexerror","i18n-japanese"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}