{"record":{"id":"5890095bf7ed2f12","repo":"krahets/hello-algo","slug":"error-589009","errorCode":null,"errorMessage":"両端キューは空です","messagePattern":"両端キューは空です","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"ja/codes/ruby/chapter_stack_and_queue/array_deque.rb","lineNumber":76,"sourceCode":"  ### キュー先頭から取り出す ###\n  def pop_first\n    num = peek_first\n    # 先頭ポインタを 1 つ後ろへ進める\n    @front = index(@front + 1)\n    @size -= 1\n    num\n  end\n\n  ### キューの末尾から取り出す ###\n  def pop_last\n    num = peek_last\n    @size -= 1\n    num\n  end\n\n  ### 先頭要素にアクセス ###\n  def peek_first\n    raise IndexError, '両端キューは空です' if is_empty?\n\n    @nums[@front]\n  end\n\n  ### キュー末尾要素を参照 ###\n  def peek_last\n    raise IndexError, '両端キューは空です' if is_empty?\n\n    # 末尾要素のインデックスを計算\n    last = index(@front + size - 1)\n    @nums[last]\n  end\n\n  ### 表示用の配列を返す ###\n  def to_array\n    # 有効長の範囲内のリスト要素のみを変換\n    res = []\n    for i in 0...size","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ja/codes/ruby/chapter_stack_and_queue/array_deque.rb#L58-L94","documentation":"Raised by ArrayDeque#peek_first (ja/codes/ruby/chapter_stack_and_queue/array_deque.rb:76) when the deque is empty. It returns @nums[@front], undefined when size == 0, so the guard blocks the read. pop_first delegates to peek_first, so removing from the front of an empty deque surfaces this too. Message: \"両端キューは空です\" (Deque is empty).","triggerScenarios":"Calling deque.peek_first or deque.pop_first when deque.size == 0 — before any push, or after the deque has been fully drained.","commonSituations":"A two-ended buffer drained from both sides past empty; deque used as a sliding window with off-by-one length checks; test harness popping in a loop without an emptiness guard.","solutions":["Check deque.is_empty? before peek_first/pop_first.","Verify deque.size >= 1 before any front-side operation.","Rescue IndexError and return nil for the empty case if empty is expected."],"exampleFix":"# before\nfront = deque.peek_first # raises on empty\n\n# after\nfront = deque.is_empty? ? nil : deque.peek_first","handlingStrategy":"validation","validationCode":"deque.peek_first unless deque.is_empty?","typeGuard":"def deque_nonempty?(d); d.respond_to?(:is_empty?) && !d.is_empty?; end","tryCatchPattern":"begin\n  deque.peek_first\nrescue IndexError\n  nil\nend","preventionTips":["Guard peek_first/pop_first with is_empty?.","Require size >= 1 before any front-side operation.","Return nil for the empty case in callers."],"tags":["ruby","deque","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"}