I would like to know how properly monkey patch a core DSL on RoR. I have the following monkey patch:
# frozen_string_literal: true
module CoreExtensions
module Numeric
def percent_of(number)
to_f / number * 100.0
end
end
end
(I've followed this article).
Now I would like to know where to put the following:
Numeric.include CoreExtensions::Numeric
I would like to have this percent_of
method available for all my app. I've tried to place it in config/application.rb
:
# frozen_string_literal: true
Rails.application.configure do
# ...
end
Numeric.include CoreExtensions::Numeric
But it didn't work. When I try to serve the following error is raised:
uninitialized constant CoreExtensions (NameError)
Thank you.