Welcome to the Treehouse Community
Looking to learn something new?
Hiromi De Young2,294 Points
Under the Ruby Boolean quiz, the question about a contains? method seems broken. Anyone else get it to work?
This code is 100% correct, yet the Ruby Boolean quiz refuses to accept it as a valid answer:
def contains?(name) @todo_items.include?(name) end
The system keeps saying "Bummer! The contains? method doesn't return a boolean value." Has anybody else been able to pass this question in order to move on?
class TodoList attr_reader :name, :todo_items def initialize(name) @name = name @todo_items =  end def add_item(name) todo_items.push(TodoItem.new(name)) end def contains?(name) @todo_items.include?(name) end def find_index(name) index = 0 found = false todo_items.each do |item| found = true if item.name == name break if found index += 1 end if found return index else return nil end end end t = TodoList.new('MyList') t.todo_items << "test" puts t.contains? "test"
Tim Knight28,863 Points
What you have here is valid Ruby but I think they're looking for a little more from you. What if
include? didn't exist? How would you check to see if todo_items contained a value? You'd iterate over the array.
def contains?(name) todo_items.each do |item| return true if item.name == name end return false end