Skip to content

Instantly share code, notes, and snippets.

@asadakbar
Created June 25, 2012 22:36
Show Gist options
  • Save asadakbar/2991892 to your computer and use it in GitHub Desktop.
Save asadakbar/2991892 to your computer and use it in GitHub Desktop.
Booster with Robert - Monday June 25th
class List
def initialize(file_path)
file_text = File.read(file_path)
parse_tasks(file_text)
end
def parse_tasks(text)
@tasks = []
text.split("\n").each do |line|
@tasks << Task.new(line.split[1..-1].join(' '))
end
end
def add_task(task_name)
@tasks << Task.new(task_name)
end
def display_tasks
every_task { |string| print string }
end
def every_task(&pizza)
puts pizza.class
#my_other_method(&pizza)
pizza.call("here's your pizza!\n")
end
def my_other_method
#yield "wtf\n"
end
def do_something
every_task do |whatever|
puts whatever + "5"
end
end
def write_to_file
file = File.open('./todo.txt', 'w') do |file|
file.write("blah\n")
end
end
end
class Task
def initialize(name)
@name = name
end
def to_s
@name
end
end
list = List.new('./todo.txt')
list.display_tasks
list.add_task('do laundry')
list.do_something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment