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

Isis van der Plas
Isis van der Plas
13,445 Points

how come the if statement returns true? in ruby booleans part 4.

how come the following if-statement returns true? I don't see it defined anywhere, and yet it works. I would get it if we first would put something like "todo_list.remove_item("eggs")", but we don't, and I would guess the default setting is false, so how does this work?

if todo_list.remove_item("eggs")
  puts "Eggs were removed from the list."
end

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

remove_items is defined and returns true or false depending on whether that item was in the list, see code under this video:

https://teamtreehouse.com/library/ruby-booleans/build-a-simple-todo-list-program/part-4-removing-todo-items