Filter nil values
The Enumerable module defines the compact method, which returns an Array containing all non-nil elements. The Hash overloads the method and returns a Hash containing all entries whose values are not nil.

In addition, Array and Hash define compact! which modifies the instance. ⚠️ The method returns nil if there is no modification.

Links to Ruby documentation for Array#compact and Hash#compact.