Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created June 23, 2012 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmandreza/2976109 to your computer and use it in GitHub Desktop.
Save kmandreza/2976109 to your computer and use it in GitHub Desktop.
ToDoList
require 'docopt'
class Task
def initialize(contents)
end
end
class Todo
# attr_accessor :ToDo
#
def initialize
# @tasks = tasks
@filename = "untitled.txt"
@tasks = File.readlines(@filename)
end
def add(task)
write_file(@tasks << task)
end
def prepend(task)
write_file(@tasks.insert(0,task))
end
#
def delete(number)
@tasks.delete_at(number.to_i - 1)
write_file(@tasks)
end
def write_file(tasks_array)
File.open(@filename, "w").puts(tasks_array)
end
end
todo = Todo.new
doc = "Usage...
-a add item Adds to the end
-p MESSAGE Adds to the beginning
-d NUM Deletes the line from the file
"
if __FILE__ == $0
command = ARGV[0]
command_arg = ARGV[1]
options = Docopt(doc)
if command == "-a"
todo.add(command_arg)
# puts "we can add, yo"
elsif command == "-p"
todo.prepend(command_arg)
elsif command == "-d"
todo.delete(command_arg)
else
"nothing"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment