Ruby Final Project - Step 5

Hi All

Having difficulty with step 5 of the Ruby Final Project. After getting repeated error messages with my own code, I gave in and copied out the solution code verbatim but still seem to be hitting a brick wall.

So code is entered as:

class List
	attr_reader :all_tasks
	if __FILE__ == $PROGRAM_NAME
		my_list = List.new
		puts "You have created a new list"
		my_list.add(Task.new("Learn Ruby"))
		puts "You have added a task to the ToDo List"
	end
	def initialize
		@all_tasks = []
	end
	def add(task)
		all_tasks << task
	end
end
class Task
	attr_reader :description
	def initialize(description)
	    @description = description
	end
end

and when running I receive the following error message:

➜my_final_Ruby_project** ruby todo.rb
You have created a new list
odo.rb:6:in `&lt;class:List&gt;': uninitialized constant List::Task (NameError)
from todo.rb:1:in `&lt;main&gt;'

From research online I can see that Uninitialized Constant is a fairly common fault but I’m not sure what’s causing it.

Could some kind soul explain where I’m going wrong?

1 Like

You might want to define your classes before you start executing them.

1 Like

Had a feeling it would be something simple I’d missed. Cheers!

1 Like