Class: TodoList
- Inherits:
-
Object
- Object
- TodoList
- Defined in:
- lib/todo_list.rb
Instance Attribute Summary collapse
-
#todo ⇒ Object
readonly
Returns the value of attribute todo.
Instance Method Summary collapse
- #add(todo) ⇒ Object
- #empty? ⇒ Boolean
- #find(search) ⇒ Object
-
#initialize ⇒ TodoList
constructor
A new instance of TodoList.
- #length ⇒ Object
- #to_array ⇒ Object
- #update(todo) ⇒ Object
Constructor Details
#initialize ⇒ TodoList
Returns a new instance of TodoList.
4 5 6 |
# File 'lib/todo_list.rb', line 4 def initialize @todo = {} end |
Instance Attribute Details
#todo ⇒ Object (readonly)
Returns the value of attribute todo.
2 3 4 |
# File 'lib/todo_list.rb', line 2 def todo @todo end |
Instance Method Details
#add(todo) ⇒ Object
8 9 10 |
# File 'lib/todo_list.rb', line 8 def add(todo) @todo.store(todo.id, todo) end |
#empty? ⇒ Boolean
24 25 26 |
# File 'lib/todo_list.rb', line 24 def empty? @todo.length == 0 end |
#find(search) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/todo_list.rb', line 12 def find(search) list = TodoList.new @todo.each do |id, todo| list.add todo if /^#{search}/.match id end list end |
#length ⇒ Object
20 21 22 |
# File 'lib/todo_list.rb', line 20 def length @todo.length end |
#to_array ⇒ Object
33 34 35 36 37 |
# File 'lib/todo_list.rb', line 33 def to_array todos = [] @todo.each do |id, todo| todos << todo end todos end |
#update(todo) ⇒ Object
28 29 30 31 |
# File 'lib/todo_list.rb', line 28 def update(todo) @todo.delete(todo.id) @todo[todo.id] = todo end |