Sha256: 3011570cc22649786ea4c562bb2577f2638e146b7d8e3b5cac086091b3bbd65d

Contents?: true

Size: 777 Bytes

Versions: 1

Compression:

Stored size: 777 Bytes

Contents

require "heredity/inheritable_class_instance_variables"

require "heredity/version"

module Heredity
  def self.included(klass)
    klass.class_eval do
      extend ::Heredity::ClassMethods
      include ::Heredity::InheritableClassInstanceVariables

      class << self
        alias_method :inheritance_eval, :on_inherit
        alias_method :inherited_eval, :on_inherit
        alias_method :when_inherited, :on_inherit
      end
    end
  end

  module ClassMethods
    def _heredity_inherited_hooks
      @_heredity_inherited_hooks ||= []
    end

    def inherited(klass)
      super

      _heredity_inherited_hooks.each do |block|
        klass.class_eval(&block)
      end
    end

    def on_inherit(&block)
      _heredity_inherited_hooks << block
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heredity-0.1.0 lib/heredity.rb