class Node    
    attr_accessor :data, :next
    def initialize(data)
        @data = data
        @next = nil
    end
end

class Linkedlist
    @head    
    def push(data)
        node = Node.new(data)
        node.next = @head 
        @head = node 
    end
    def pop()
        unless @head == nil
            data = @head.data
            @head = @head.next
            return data
        end
    end
end

list = Linkedlist.new
list.pop
list.push(200)
list.push(100)
p list
p list.pop
p list.pop
p list

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: