Created
October 15, 2012 06:03
-
-
Save BrianJoyce/3891014 to your computer and use it in GitHub Desktop.
todo_Arne
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TodoFile | |
| attr_accessor :todo_file | |
| def initialize(filename) | |
| @filename = filename | |
| end | |
| def read(access='r') | |
| @todo_file = File.open(@filename, access) | |
| end | |
| def write(todo_list) | |
| # open_file("w") | |
| todo_list.each {|task| @file << task} | |
| close_file | |
| end | |
| def write_todo(single_todo) | |
| read('a') | |
| @todo_file << single_todo + "\n" | |
| close_file | |
| end | |
| def close_file | |
| @todo_file.close | |
| end | |
| end | |
| class TodoList | |
| def list(my_file) | |
| my_file.each_with_index {|task, n| puts "#{n+1}. #{task}"} | |
| end | |
| def append(new_todo) | |
| new_todo | |
| end | |
| end | |
| class Todo | |
| attr_accessor :todo | |
| def initialize(todo) | |
| @todo = todo | |
| end | |
| end | |
| my_file = TodoFile.new("task_list.txt") | |
| my_file.read | |
| my_todo_list = TodoList.new | |
| my_todo_list.list(my_file.read) | |
| # my_file.write("get laid") | |
| another_todo = Todo.new("Get some tail") | |
| # puts my_todo_list.append(another_todo.todo) | |
| my_file.write_todo(my_todo_list.append(another_todo.todo)) | |
| # def list | |
| # open_file("r") | |
| # all_tasks | |
| # @tasks.each_with_index do |task, n| | |
| # puts "#{n+1}. #{task}" | |
| # end | |
| # close_file | |
| # end | |
| # todolist = TodoList.new | |
| # todolist.add(todo) | |
| # todolist.delete(num) | |
| # todolist.list | |
| # todolist.add | |
| # | |
| # my_to_do_list = Todo_list.new | |
| # my_to_do_list.list(my_file) | |
| # | |
| # class TodoList | |
| # | |
| # def initialize | |
| # @file = FileManager.new | |
| # | |
| # end | |
| # end | |
| # | |
| # # inside -- the design of your system | |
| # ############################################ | |
| # # outside -- using your system | |
| # | |
| # todo = Todo.new | |
| # todo.id | |
| # todo.complete? | |
| # todo.tags #=> [<Tag>, <Tag>] | |
| # todo.text | |
| # todo.time | |
| # todo.date | |
| # | |
| # | |
| # todolist = TodoList.new | |
| # todolist.add(todo) | |
| # todolist.delete(num) | |
| # todolist.list | |
| # todolist.add | |
| # | |
| # file.write(todolist) | |
| # file.read(filename, access) | |
| # | |
| # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment