Learn Ruby - Final Project Issue


#1

Hi All - this is my first time using the community forum for getting help. Hopefully I’m doing it right…

I (think) I have run into an issue with my final project, I am on Step 6 where we are asked to display All Tasks. I’ve got my code running well, but when I run the project from the command line the tasks that I have entered appear as memory locations, like so:

Justins-iMac:Desktop schilb_home$ ruby Todo.rb
You have created a new list.
You have added a task to the ToDo List!
#<Task:0x00007f8ec5858288>
#<Task:0x00007f8ec5858238>
#<Task:0x00007f8ec58581c0>

Any thoughts on what I might be doing wrong? I tried to upload a txt file of my code but since I’m a new user it wouldn’t let me.


#2

It looks like possibly a misreference of the object or method. Please post the URL of the project page, and you can post your code, just paste it in, select it all at once, and click the </> button in tool tray of the editor window.


#3

I have the same problem! Here’s my code:

module Menu
	def menu
		" Welcome to your to do list! 
		This menu will help you use the task list system
		1) Add
		2) Show
		Q) Quit "
	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)
		@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(my_list)
          puts 'Please choose from the following list:' 
          	until ['q'].include?(user_input = prompt(show).downcase)
          		case user_input
					when "1"
						my_list.add(Task.new(prompt('What is the task you would like to accomplish?')))
					when "2"
						puts my_list.show
					else
						puts "Sorry, I did not understand"
				end
          	end
          puts 'Outro - Thanks for using the menu system!'
      end 

#4

I just recently started the Ruby course and have the same problem. I noticed if I remove the reference for creating a Task object the program runs. So instead of ```
my_list.add(Task.new(‘Make Breakfast’))

If I used
**my_list.add('Make Breakfast')**
the code runs with no issue and passes the suggested ```
**if my_list.show.join.include?('#<')**

I am pretty sure this is not the solution but I am not sure why including the
my_list.add(Task.new(‘Make Breakfast’))
returns #Task:... results instead of just the listed tasks.