Sha256: b8dc0f554df4e6a40712e45d291b01325b016a8dcec759fb3c1314bc917f6ac7

Contents?: true

Size: 889 Bytes

Versions: 18

Compression:

Stored size: 889 Bytes

Contents

module Pancake
  module Hooks
    module OnInherit
      def self.extended(base)
        base.class_eval do
          class_inheritable_reader :_on_inherit
          @_on_inherit = []
        end
      end
    
      # Provides an inheritance hook to all extended classes
      # Allows ou to hook into the inheritance 
      def inherited(base)
        super
        _on_inherit.each{|b| b.call(base,self)}
      end
    
      # A hook to add code when the stack is inherited
      # The code will be executed when the class is inherited
      # 
      # @example 
      #   MyClass.on_inherit do |base, parent|
      #     # do stuff here between the child and parent
      #   end
      #
      # @api public
      # @author Daniel Neighman
      def on_inherit(&block)
        _on_inherit << block if block
        _on_inherit
      end
    end # OnInherit
  end # Hooks
end # Pancake

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
hassox-pancake-0.1.6 lib/pancake/hooks/on_inherit.rb
pancake-0.1.29 lib/pancake/hooks/on_inherit.rb
pancake-0.1.28 lib/pancake/hooks/on_inherit.rb
pancake-0.1.27 lib/pancake/hooks/on_inherit.rb
pancake-0.1.26 lib/pancake/hooks/on_inherit.rb
pancake-0.1.25 lib/pancake/hooks/on_inherit.rb
pancake-0.1.24 lib/pancake/hooks/on_inherit.rb
pancake-0.1.22 lib/pancake/hooks/on_inherit.rb
pancake-0.1.20 lib/pancake/hooks/on_inherit.rb
pancake-0.1.19 lib/pancake/hooks/on_inherit.rb
pancake-0.1.18 lib/pancake/hooks/on_inherit.rb
pancake-0.1.17 lib/pancake/hooks/on_inherit.rb
pancake-0.1.16 lib/pancake/hooks/on_inherit.rb
pancake-0.1.15 lib/pancake/hooks/on_inherit.rb
pancake-0.1.13 lib/pancake/hooks/on_inherit.rb
pancake-0.1.12 lib/pancake/hooks/on_inherit.rb
pancake-0.1.10 lib/pancake/hooks/on_inherit.rb
pancake-0.1.8 lib/pancake/hooks/on_inherit.rb