Sha256: 21c53461c05b284a94dfaccde515a57f29ed9872f294a3634cb120d4c90bca5b

Contents?: true

Size: 478 Bytes

Versions: 1

Compression:

Stored size: 478 Bytes

Contents

require_relative "./errors"

module Interceptors
  module DS
    class Stack
      include DS::Errors

      def initialize
        @head = nil
      end

      def push(item)
        assert!(item)
        old_head = @head
        @head = Node.new(item)
        @head.next = old_head
      end

      def pop
        raise NoSuchElementException if empty?

        @head.item.tap { @head = @head.next }
      end

      def empty?
        @head.nil?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
interceptors-0.1.1 lib/interceptors/ds/stack.rb