Skip to content

Instantly share code, notes, and snippets.

@mattb20
Created March 16, 2018 15:59
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 mattb20/8058a970219136a27d0955483849153a to your computer and use it in GitHub Desktop.
Save mattb20/8058a970219136a27d0955483849153a to your computer and use it in GitHub Desktop.
How to properly generate an instance of Todolist?
class Todo
def initialize(string)
@to_do = string
end
def text
puts @to_do
end
end
class Todolist < Array
def initialize
@to_do_list = []
end
def add(task_to_do)
@to_do_list.push(task_to_do)
end
def print
@to_do_list.each do |task|
puts "*" + task
end
end
end
Todolist.new
Todo.new("get the milk")
p @to_do_list.class #returns NilClass
@to_do_list.add(@to_do)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment