I am having an error in my program with the show method. On the bottom of page 7/13 of the Ruby final project, they include the solution code to the program. I checked, double checked and triple checked. I am running identical code unless somehow I missed something.
My menu is currently only
'1' Adds a new task
'2' Displays the list
'Q' quits the app
Adding a task to the program seems to run fine. But when I Display the list I get an error that looks something like
#<Task:0x00000000028857f0>
…great.
So I added a “.to_s” to “puts my_list.show” because I am trying to make something happen with my limited knowledge.
case user_input
when '1'
my_list.add(Task.new(prompt("What Task would you like to add?")))
when '2'
puts my_list.show.to_s
else
puts "Say again?"
end
Now I run the program, add a task go to show the list and!?
[#<Task:0x00000000028857f0 @description="Shibby Dibby Doo">]
Okay, we are getting somewhere…maybe.
Now it’s in array brackets, and showing the instance variable @description. Then the actual Task I added “Shibby Dibby Doo”.
I’ve been stuck here for quite a bit now. Please if you can lend a hand, I’d very much appreciate it!
Here is all the code I’ve written so far.
module Menu
def menu
"Please choose from the following...
'1' Adds a new Task
'2' Displays the List
'Q' Quits the app"
end
def show
menu
end
end
module Promptable
def prompt(message = "What would you like to do?", symbol = ":> ")
print message
print symbol
gets.chomp
end
end
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
if __FILE__ == $PROGRAM_NAME
include Menu
include Promptable
my_list = List.new
puts "Welcome to Vaughn's TO DO List Program!"
until ['q'].include?(user_input = prompt(show).downcase)
case user_input
when '1'
my_list.add(Task.new(prompt("What Task would you like to add?")))
when '2'
puts my_list.show.to_s
else
puts "Say again?"
end
end
puts "Thanks for using Vaughn's TO DO List!"
end