pub(crate) fn retain<F>(&mut self, mut f: F) -> Result<bool, RubyError>
    where
        F: FnMut(&Value) -> Result<bool, RubyError>,
    {
        let len = self.len();
        let mut del = 0;
        {
            let v = &mut **self;
            for i in 0..len {
                if !f(&v[i])? {
                    del += 1;
                } else if del > 0 {
                    v.swap(i - del, i);
                }
            }
        }
        if del > 0 {
            self.truncate(len - del);
        }
        Ok(del != 0)
    }
Retains only elements which f(elem) returns true.

Returns true when one or some elements were removed.
ruruby/src/value/array.rs