class Taskinator::Tasks

Attributes

count[R]
first[R]

implements a linked list, where each task references the next task

head[R]

implements a linked list, where each task references the next task

length[R]

Public Class Methods

new(first=nil) click to toggle source
# File lib/taskinator/tasks.rb, line 13
def initialize(first=nil)
  @count = 0
  add(first) if first
end

Public Instance Methods

<<(task)
Alias for: add
add(task) click to toggle source
# File lib/taskinator/tasks.rb, line 24
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
Also aliased as: <<, push
attach(task, count) click to toggle source
# File lib/taskinator/tasks.rb, line 18
def attach(task, count)
  @head = task
  @count = count
  task
end
each() { |current| ... } click to toggle source
# File lib/taskinator/tasks.rb, line 46
def each(&block)
  return to_enum(__method__) unless block_given?

  current = @head
  while current
    yield current
    current = current.next
  end
end
empty?() click to toggle source
# File lib/taskinator/tasks.rb, line 42
def empty?
  @head.nil?
end
inspect() click to toggle source
# File lib/taskinator/tasks.rb, line 56
def inspect
  %([#{collect(&:inspect).join(', ')}])
end
push(task)
Alias for: add