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 4: Removing Todo Items

John Bamberg
John Bamberg
9,774 Points

Why "s"

Sometimes it reads "todo_item" and others "todo_items" Why?

3 Answers

Sage Elliott
Sage Elliott
30,003 Points

Hello, john. They are actually two different objects. The "todo_items" array can contain multiple "todo_item" objects. "eggs" is an example of a todo_item. It can then be added to the todo_items list which may contain another item or can have another item added to it. I hope that helped!

John Bamberg
John Bamberg
9,774 Points

ok so what would you call "todo_items.each"? "do"? "|todo_item|"? On line 4

def remove_item(name)
index = 0
found = false
todo_items.each do |todo_item|
  if todo_item.name == name
    found = true
  end
  if found
    break
  else
    index += 1
  end
end
if found
  todo_items.delete_at(index)
  return true
else
  return false
end

end

Grzegorz Gancarczyk
Grzegorz Gancarczyk
10,064 Points

I know it's too late to make an answer but maybe it will help other people. In my opinion in line 4 we are looping through todo_items which is an array (look at: todo_items = []) to look for a todo_item which is every item in the array. So, in other words - we are searching our Groceries list for Milk or Eggs.