I have two classes List and Task:
class List
attr_reader :all_tasks
def initialize
@all_tasks = []
end
def add (task)
@all_tasks << task
end
def show
all_tasks
end
end
class Task
attr_reader :description
def initialize (description)
@description = description
end
end
And the following code:
breakfast = Task.new("Make Breakfast")
my_list = List.new
my_list.add(breakfast)
my_list.add(Task.new("Wash the dishes!"))
my_list.add("Send Birthday Gift to Mom")
puts "Your task list:"
puts my_list.show
Output:
Your task list:
#<Task:0x00007fd9e4849ed0>
#<Task:0x00007fd9e4849e30>
Send Birthday Gift to Mom
I want to be able to show the tasks of the to-do list as a string and in the same time have the Task instances as objects inside the array. How do I do that?
attr_reader :all_taskslooks like read-only, it allows the caller to modifyall_tasks, e.g.my_list.all_tasks << 'another task'.