title: Accessing Ruby class methods with io console
body: <p>I'm creating a simple task manager in Ruby and am having trouble running a class method on an object that I've created.  Here's my backend code:</p>
  
  <pre><code>class TM::Project
    attr_accessor :name, :pid, :tasks
    @@projects = []
  
    def initialize(name=nil)
      @name = name
      @pid = @@projects.size
      @tasks = []
      @@projects &lt;&lt; self
    end
  
    def add_task(priority, description)
      task = TM::Task.new(priority, description)
      @tasks &lt;&lt; task
    end
  end
  
  class TM::Task
    attr_accessor :tid, :description, :priority, :status, :creation_date
    @@tasks = []
  
    def initialize(priority, description)
      @description = description
      @priority = priority
      @tid = @@tasks.size
      @@tasks &lt;&lt; self
      @status = "incomplete"
      @creation_date = Time.now
    end
  end
  </code></pre>
  
  <p>And here's the code for the console: </p>
  
  <pre><code>require_relative 'lib/task-manager.rb'
  
  class Task_io
    @@io_projects = []
  
    def start
      puts "Welcome to Task Manager.  How may we assist you?\n\n"
  
      puts "Available Commands: \n"
      puts "  create NAME - Create a new project with name=NAME"
      puts "  add PID PRIORITY DESC - Add a new task to project with id=PID"
  
      puts 'Enter request&gt;'
      req = gets.chomp
      input = req.split
  
      if input[0] == 'create'
          proj = TM::Project.new(input[1])
          puts "#{proj.name} was created with ID=#{proj.pid}"
          @@io_projects &lt;&lt; proj
          self.start
      elsif input[0] == 'add'
          i = 0
          proj_id = input[1].to_i
          @@io_projects[proj_id].add_task(input[2], input[3].to_s)
          puts "#{input[3].to_s} was assigned TID #{@@tasks[i + 1]}"
          i += 1
          self.start
      else
        puts "Invalid request, please try again"
        self.start
      end
    end
  end
  </code></pre>
  
  <p>I'm able to create projects, but when I try to add a task to the project I get the following error:</p>
  
  <pre><code>undefined method `add_task' for nil:NilClass
  </code></pre>
  
  <p>Am I accessing the object incorrectly?</p>