{"record":{"id":"34075d588af5122f","repo":"krahets/hello-algo","slug":"error-34075d","errorCode":null,"errorMessage":"стек пуст","messagePattern":"стек пуст","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"ru/codes/ruby/chapter_stack_and_queue/array_stack.rb","lineNumber":31,"sourceCode":"\n  ### Получить длину стека ###\n  def size\n    @stack.length\n  end\n\n  ### Проверка, пуст ли стек ###\n  def is_empty?\n    @stack.empty?\n  end\n\n  ### Помещение в стек ###\n  def push(item)\n    @stack << item\n  end\n\n  ### Извлечение из стека ###\n  def pop\n    raise IndexError, 'стек пуст' if is_empty?\n\n    @stack.pop\n  end\n\n  ### Доступ к верхнему элементу стека ###\n  def peek\n    raise IndexError, 'стек пуст' if is_empty?\n\n    @stack.last\n  end\n\n  ### Вернуть список для вывода ###\n  def to_array\n    @stack\n  end\nend\n\n### Driver Code ###","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/ruby/chapter_stack_and_queue/array_stack.rb#L13-L49","documentation":"Raised by ArrayStack#pop (ru) when the stack is empty. ArrayStack backs onto Ruby's built-in Array (so there is NO capacity limit and no 'full' error ever). The guard preempts `@stack.pop`, which Ruby would otherwise return nil for — the library chooses to raise IndexError 'стек пуст' instead of silently returning nil.","triggerScenarios":"Calling `stack.pop` on a never-pushed stack, or after the last element was popped. Any pop loop that overshoots triggers it.","commonSituations":"Unwinding all frames then popping once more; mismatched push/pop counts; an algorithm that pops to verify emptiness without checking first.","solutions":["Guard with `stack.is_empty?` before pop.","Drive pop loops with `while stack.size > 0`.","Wrap pop in a helper returning nil on empty for optional semantics."],"exampleFix":"// before\nval = stack.pop  # raises 'стек пуст' when empty\n\n// after\nval = stack.is_empty? ? nil : stack.pop","handlingStrategy":"validation","validationCode":"val = stack.pop unless stack.is_empty?","typeGuard":"def stack_nonempty?(s) = !s.is_empty?","tryCatchPattern":"begin\n  val = stack.pop\nrescue IndexError\n  val = nil\nend","preventionTips":["Guard pop with is_empty? (ArrayStack has no capacity limit, only empty raises).","Drive pop loops with `while stack.size > 0`.","Wrap pop in a helper if you prefer nil over a raise."],"tags":["ruby","stack","array-backed","empty-state","index-error"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}