to clarify why that works, it's because Array#delete returns the deleted value if it was found, and nil if it wasn't.  Meanwhile !! is a rubyism for casting to boolean.  Additionally Array#delete modifies the array in-place, so :state will no longer be present in the array, so the middle line won't get tripped up by its presence.