Sha256: 9eb87548c9b2fcf90f6b6688d1b01d1dbfcaa9a21ceeef8abf7cc23a7e02a04f

Contents?: true

Size: 922 Bytes

Versions: 2

Compression:

Stored size: 922 Bytes

Contents

require 'before_hooks/version'

module BeforeHooks
  # `base` is expected to be and should be an `Object`
  def self.prepended(base)
    base.singleton_class.send(:prepend, ClassMethods)
  end

  module ClassMethods
    def extend(*modules)
      modules.each do |_module|
        if _module.singleton_class.instance_methods.include? :before_extended
          _module.before_extended(self)
        end
      end

      super
    end

    def include(*modules)
      modules.each do |_module|
        if _module.singleton_class.instance_methods.include? :before_included
          _module.before_included(self)
        end
      end

      super
    end

    def prepend(*modules)
      modules.each do |_module|
        if _module.singleton_class.instance_methods.include? :before_prepended
          _module.before_prepended(self)
        end
      end

      super
    end
  end
end

Object.send(:prepend, BeforeHooks)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
before_hooks-0.1.1 lib/before_hooks.rb
before_hooks-0.1.0 lib/before_hooks.rb