Undefined method '<<' Error


Just started the final project. When I try to push the task into the all_tasks array I get the following error:
todo.rb:7:inadd_task’: undefined method <<' for nil:NilClass (NoMethodError)

class List
  attr_reader :all_tasks
  def intialize
    @all_tasks = []
  def add_task(task)
    @all_tasks << task

class Task
  attr_reader :description
  def initialize(description)
    @description = description

  my_list = List.new
  puts 'You have created a new list'
  my_list.add_task(Task.new('Make Breakfast'))
  puts 'You have added a task to the Todo List'

What exactly am I doing wrong? I am using cloud 9 to write all my code.


Please remember to include a link to the exercise when posting a question in Q&A. Thanks.

Does that look right to you?

We can trace this error message back to that typo, since as a result the array @all_tasks does not exist, so cannot have a push method. That is what nil:NilClass means. nil does not have any methods or attributes.


Thanks. I need to rest, apparently my eyes aren’t working.


Thanks a bunch! I’ll have to be more careful. At least it was a learning experience!


That’s great! You’re welcome. Expect lots more of little trip-ups along your way. It happens, and the more it does, the more chance we have to sharpen up on the little details AND muscle memory, troubleshooting memory, etc. Mistakes are our friends.