-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToDoList.rb
73 lines (55 loc) · 1.21 KB
/
ToDoList.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class Task
attr_reader :content, :id, :completed
@@current_id = 1
def initialize(content = "dog")
@content = content
@id = @@current_id
@@current_id += 1
@completed = false
@created_at = Time.new
@updated_at = nil
end
def completed?
@completed
end
def completed!
@completed = true
end
def make_incomplete!
@completed = false
end
def update_content(new_content)
log_update
@content = new_content
end
def log_update
@updated_at = Time.new
end
end
# class TodoList
# attr_reader :tasks
# def initialize(user)
# @tasks = []
# @user = user
# end
# def add_task(task)
# @tasks << task
# end
# def delete_task(id)
# @tasks.delete_if{|task| task.id == id}
# end
# def find_task_by_id(id)
# n = @tasks.find_index {|item| item.id == id}
# if n == nil
# puts "nil!"
# else
# tasks[n]
# end
# end
# end
# todo_list = TodoList.new
# todo_list.add_task(Task.new("Walk the dog"))
# todo_list.add_task(Task.new("Buy the milk"))
# task = todo_list.find_task_by_id(1)
# puts task.content
# puts task.id