All methods on one object but organized in many files

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the architecture category.

Last Updated: 2024-12-03

I noticed the Ruby Spring open-source library split apart functionality nicely into different files yet retaining the API methods available under Spring.x

I liked how they combined an API condensed onto one object, but the code organization across many files.

Here's how they achieved this:

# failsafe_thread.rb
require 'thread'

module Spring
  class << self
    def failsafe_thread
      Thread.new {
        begin
          yield
        rescue
        end
      }
    end
  end
end