Auto-registering composition

Topics: Ruby

This example lets included Ruby modules register themselves in a collection.

How Ruby objects can register themselves in a collection:

module Example
  class << self
    attr_reader :registered
  end

  def self.include(base)
    (@registered ||= []) << base
  end
end