Here's a version that passes your test and doesn't require a class method:

```ruby
    def to_hash
      out = {}
      self.each do |k,v|
        out[k] = if v.is_a?(Array)
          v.map { |e| e.respond_to?(:to_hash) ? e.to_hash : e }
        else
          e.respond_to?(:to_hash) ? v.to_hash : e
        end
      end
      out
    end
```