Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Booleans Build a Simple Todo List Program Part 1: Write the Classes

Jared Armes
PLUS
Jared Armes
Courses Plus Student 6,391 Points

Correct code still returns error

I am having an issue with this code. No matter how many times I type it and check over it, I still received an error. I even tried copying the code in the work notes underneath the video to no avail. Here is the aforementioned code:


todo_list.rb

require "./todo_item"

class TodoList
  attr_reader :name, :todo_items

  def initialize(name)
    @name = name
    @todo_items = []
  end
end

todo_list = TodoList.new("Groceries")
todo_item = TodoItem.new("Milk")

puts todo_list.inspect
puts todo_item.inspect

todo_item.rb

class TodoItem
  attr_reader :name

  def initialize(name)
    @name = name
    @complete = false
  end
end

As you can see, it is literally the exact same code as was used in the video. Here is the error message that I am receiving:

irb(main):007:0> ruby todo_list.rb                                             
NameError: undefined local variable or method `todo_list' for main:Object      
        from (irb):7                                                           
        from /usr/local/bin/irb:11:in `<main>'

If I am overlooking anything, please let me know. Otherwise--something seems to be broken!

1 Answer

Taylor Boudreau
Taylor Boudreau
7,285 Points

Hi there Jared! It looks like you're trying to run the program from irb, is that correct? You can exit irb with exit and then running ruby todo_list.rb should get you going.

To run the files from irb, I believe you would have to load them in first, but I'm not there yet, so couldn't give advice for you there.

Jared Armes
Jared Armes
Courses Plus Student 6,391 Points

Wow.... Thank you. I can't believe that I overlooked this fact. I feel so dumb, haha!