The best sample I've found doing this in Rails is to drop modules that want private methods and use the Singleton class instead. It doesnโt feel good, but it works and seems cleaner than other examples that I saw in this question.
I would like to hear other opinions on this matter.
Example:
ErrorService.notify("Something bad happened") class ErrorService include Singleton class << self delegate :notify, to: :instance end def notify(message, severity: :error) send_exception_notification(message) log_message(message, severity) end private def send_exception_notification(message) # ... end def log_message(message, severity) # ... end end
Gerry Shaw Nov 09 '16 at 6:54 2016-11-09 06:54
source share