Sha256: 0f1ac2533c59f813c815adde85679b81a57de6a781117ffa15b608727a1e39d8

Contents?: true

Size: 802 Bytes

Versions: 8

Compression:

Stored size: 802 Bytes

Contents

module Erector
  module AfterInitialize
    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      def after_initialize(instance=nil, &blk)
        if blk
          after_initialize_parts << blk
        elsif instance
          if superclass.respond_to?(:after_initialize)
            superclass.after_initialize instance
          end
          after_initialize_parts.each do |part|
            instance.instance_eval &part
          end
        else
          raise ArgumentError, "You must provide either an instance or a block"
        end
      end

      protected
      def after_initialize_parts
        @after_initialize_parts ||= []
      end
    end

    def initialize(*args, &blk)
      super
      self.class.after_initialize self
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
erector-0.10.0 lib/erector/after_initialize.rb
erector-0.9.0 lib/erector/after_initialize.rb
erector-0.9.0.pre1 lib/erector/after_initialize.rb
erector-0.8.3 lib/erector/after_initialize.rb
erector-0.8.2 lib/erector/after_initialize.rb
honkster-erector-0.8.1 lib/erector/after_initialize.rb
erector-0.8.1 lib/erector/after_initialize.rb
erector-0.8.0 lib/erector/after_initialize.rb