{"record":{"id":"44d299a379627f3c","repo":"krahets/hello-algo","slug":"error-44d299","errorCode":null,"errorMessage":"キューがいっぱいです","messagePattern":"キューがいっぱいです","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"ja/codes/ruby/chapter_stack_and_queue/array_queue.rb","lineNumber":31,"sourceCode":"  def initialize(size)\n    @nums = Array.new(size, 0) # キュー要素を格納する配列\n    @front = 0 # 先頭ポインタ。先頭要素を指す\n    @size = 0 # キューの長さ\n  end\n\n  ### キューの容量を取得 ###\n  def capacity\n    @nums.length\n  end\n\n  ### キューが空か判定 ###\n  def is_empty?\n    size.zero?\n  end\n\n  ### エンキュー ###\n  def push(num)\n    raise IndexError, 'キューがいっぱいです' if size == capacity\n\n    # 末尾ポインタを計算し、末尾インデックス + 1 を指す\n    # 剰余演算により、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","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ja/codes/ruby/chapter_stack_and_queue/array_queue.rb#L13-L49","documentation":"Raised by ArrayQueue#push (ja/codes/ruby/chapter_stack_and_queue/array_queue.rb:31) when the queue is full (size == capacity). Unlike Ruby's stdlib (which grows), this teaching ArrayQueue has FIXED capacity set at construction (ArrayQueue.new(n)); push guards the rear slot to avoid overwriting unread elements in the circular buffer. Message: \"キューがいっぱいです\" (Queue is full).","triggerScenarios":"Calling queue.push(num) when queue.size == queue.capacity. Occurs after filling all n slots without popping, or in a circular enqueue/dequeue loop that enqueues more than it dequeues. Note: the English sibling (array_queue.rb) raises \"Queue is full\" with the same trigger.","commonSituations":"Constructing the queue with too small a capacity for the workload; producer outrunning the consumer in a fixed buffer; reusing the driver's size-10 queue for more than 10 simultaneous items.","solutions":["Construct ArrayQueue.new with a capacity larger than your maximum live element count.","Drain (pop) before pushing when size == capacity, or skip the push if stale data is acceptable.","Switch to a growable structure (linked-list queue, or stdlib) if the bound is unknown — this ArrayQueue cannot resize."],"exampleFix":"# before\nqueue = ArrayQueue.new(5)\n6.times { |i| queue.push(i) } # raises on the 6th\n\n# after\nqueue = ArrayQueue.new(10) # size to your peak live count\n# or guard:\nqueue.push(x) unless queue.size == queue.capacity","handlingStrategy":"validation","validationCode":"queue.push(num) unless queue.size == queue.capacity","typeGuard":"def queue_has_room?(q); q.respond_to?(:size) && q.respond_to?(:capacity) && q.size < q.capacity; end","tryCatchPattern":"begin\n  queue.push(num)\nrescue IndexError\n  # full: drop oldest, resize via new instance, or back-pressure\n  queue.pop\n  retry\nend","preventionTips":["Size the ArrayQueue's capacity to your peak live element count at construction.","Remember this queue is FIXED capacity — it cannot grow like stdlib.","Pop before pushing when size == capacity, or apply back-pressure to the producer."],"tags":["ruby","queue","circular-array","fixed-capacity","precondition","indexerror","i18n-japanese"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}