Created
March 16, 2018 15:59
-
-
Save mattb20/8058a970219136a27d0955483849153a to your computer and use it in GitHub Desktop.
How to properly generate an instance of Todolist?
This file contains 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 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