I am upgrading a Rails 5.2.2 to Rails 6.0.0 that now has Zeitwerk.
Previously I had been extended core ruby classes like Date, Time, String, Float etc as described in this question. Using an initializers file to load all files from the lib/core_ext/*
folder. When starting a rails server
it now errors an the last line of the stacktrace reads:
/home/username/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/zeitwerk-2.1.10/lib/zeitwerk/loader.rb:351:in `const_get': uninitialized constant CoreExt::Date (NameError)
Unfortunately, Zeitwerk is causing an error where lib/core_ext/date.rb
etc is throwing an error that it has already been defined (when using Rails.autoloaders.log!
in application.rb
. CoreExt::Date
I have since moved the files directly to initializers
(previously I just had the initializers directory with a file that loaded each file from the 'lib/core_ext/*
folder). This has fixed the issue for now but I'd like to keep core_ext
folder and files where they were.
What have I missed here?
lib/core_ext/date.rb
class Date
def to_sap
strftime('%d.%m.%Y')
end
end
I have tried wrapping explicitly in CoreExt
but that did not help.
module CoreExt
class Date
def to_sap
strftime('%d.%m.%Y')
end
end
end