Sha256: 124a8a312958781b28ea6fcf4f7aab758a6d4b59582f01b7ea7e167bb140485c
Contents?: true
Size: 1.02 KB
Versions: 17
Compression:
Stored size: 1.02 KB
Contents
module Taskinator class Tasks include Enumerable # implements a linked list, where each task references the next task attr_reader :head alias_method :first, :head attr_reader :count alias_method :length, :count def initialize(first=nil) @count = 0 add(first) if first end def attach(task, count) @head = task @count = count task end def add(task) if @head.nil? @head = task @count = 1 else current = @head while current.next current = current.next end current.next = task @count += 1 end task end alias_method :<<, :add alias_method :push, :add def empty? @head.nil? end def each(&block) return to_enum(__method__) unless block_given? current = @head while current yield current current = current.next end end def inspect %([#{collect(&:inspect).join(', ')}]) end end end
Version data entries
17 entries across 17 versions & 1 rubygems