lib/taskinator/tasks.rb in taskinator-0.3.10 vs lib/taskinator/tasks.rb in taskinator-0.3.11
- old
+ new
@@ -5,22 +5,34 @@
# 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)
- @head = first
+ @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