Before Rails 6 there was a simple way to split any Ruby class into multiple files without introducing any additional modules or concerns. It was quite useful for those God classes which happened to be a bit too large to be kept in one file:
# god.rb
class God < ApplicationRecord
require_dependency 'god~callbacks'
require_dependency 'god~scopes'
require_dependency 'god~search'
require_dependency 'god~something_else'
require_dependency 'god~and_more'
require_dependency 'god~and_even_more'
...
end
# god~callbacks.rb
class God
before_save :nullify_blanks
before_save :nullify_unrelated_attrs
...
end
and the file structure has looked like this:
models/
god.rb
god~callbacks.rb
god~scopes.rb
god~search.rb
...
And that has worked great — anytime you change anything in any of those files the changes were correctly reloaded.
Since Rails 6 a new class loader is used — the Zeitwerk. And that's great but seems that it doesn't work with require_dependency, at least when that method is used in such a non-typical way.
So the question is, is it possible to split a class definition into a few files and keep the auto-reloading working with Zeitwerk. And the goal is to split a class without introducing any inner modules/concerns.
And please, no need to comment on whether a 1000-line long class is a good design practice or not, that's not the point of the question.