I have an array of todos [Todo1, Todo2, Todo3]
Each object has an attribute, :done_date
I need to find the first instance of the object where :done_date => null
THEN I need to know what index it is todos[N] so I can find the object before todos[N-1]
How can I do that?
You could try going about it in a slightly different way. Making use of Ruby’s
Enumerable#take_while:This will get all todo objects from
todosuntil it sees a nildone_date, and then grab the last one. You’ll have the last todo item before the first nildone_date.So, if you have
the code example above will return
todo3.That said, if you’re really looking for something that makes use of the array’s indicies, you could try something like this as well: