I think you can do:

```ruby
package_groups.each_with_object([]) { |attrs, groups| groups << ::PackageGroup.new(attrs) if attrs }
```