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 Instantiation and Methods

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

Ruby Booleans - Challenge Task 4 of 4: Can't append to array

I am having some issues with the syntax of this challenge. I know that I will need to initiate a new instance of the TodoItem class, and assign it to the argument. I just don't know how to append this data into the todo_items array. Any help would be greatly appreciated!

todo_list.rb
class TodoList
  attr_reader :name, :todo_items

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

  def add_item(item)
    item = TodoItem.new
    todo_items.push(item)
  end

end

1 Answer

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Really close, remember to instantiate item and push that to the array. Watch the previous video at about 1min.

  def add_item(item)
    todo_items.push(TodoItem.new(item))
  end
Jared Armes
Jared Armes
Courses Plus Student 6,302 Points

Awesome... Thank you so much for the quick and thorough reply! This is why Treehouse rocks.