Class: Taskinator::Tasks
- Inherits:
-
Object
- Object
- Taskinator::Tasks
- Includes:
- Enumerable
- Defined in:
- lib/taskinator/tasks.rb
Instance Attribute Summary collapse
-
#head ⇒ Object
(also: #first)
readonly
implements a linked list, where each task references the next task.
Instance Method Summary collapse
- #add(task) ⇒ Object (also: #<<, #push)
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(first = nil) ⇒ Tasks
constructor
A new instance of Tasks.
Constructor Details
#initialize(first = nil) ⇒ Tasks
Returns a new instance of Tasks.
10 11 12 |
# File 'lib/taskinator/tasks.rb', line 10 def initialize(first=nil) @head = first end |
Instance Attribute Details
#head ⇒ Object (readonly) Also known as: first
implements a linked list, where each task references the next task
7 8 9 |
# File 'lib/taskinator/tasks.rb', line 7 def head @head end |
Instance Method Details
#add(task) ⇒ Object Also known as: <<, push
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/taskinator/tasks.rb', line 14 def add(task) if @head.nil? @head = task else current = @head while current.next current = current.next end current.next = task end task end |
#each(&block) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/taskinator/tasks.rb', line 34 def each(&block) return to_enum(__method__) unless block_given? current = @head while current yield current current = current.next end end |
#empty? ⇒ Boolean
30 31 32 |
# File 'lib/taskinator/tasks.rb', line 30 def empty? @head.nil? end |