Sha256: 13066152eeccee9e23eb06ba770efc56ea88a175b81460e564599b2dfa444ef4

Contents?: true

Size: 660 Bytes

Versions: 45

Compression:

Stored size: 660 Bytes

Contents

# def initialize
#   after_initialize
# end
# 
module InitializerHooks
  
  mattr_accessor :hooks # { class => [blocks] }
  self.hooks = {}
  
  # Calls the hooks in order of registration.
  #
  def after_initialize
    hooks = InitializerHooks.hooks[self.class]
    hooks && hooks.each do |hook|
      self.instance_eval &hook
    end
  end
  
  # Registers a hook for a class.
  #
  def self.register klass, &hook
    self.hooks[klass] ||= []
    self.hooks[klass] << hook
  end
  
  def self.prepend klass, &hook
    self.hooks[klass] ||= []
    self.hooks[klass].unshift hook
  end
  def self.append klass, &hook
    self.register klass, &hook
  end
  
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
gosu_extensions-0.3.5 lib/core/initializer_hooks.rb
gosu_extensions-0.3.4 lib/core/initializer_hooks.rb
gosu_extensions-0.3.3 lib/core/initializer_hooks.rb
gosu_extensions-0.3.2 lib/core/initializer_hooks.rb
gosu_extensions-0.3.1 lib/core/initializer_hooks.rb
gosu_extensions-0.3.0 lib/core/initializer_hooks.rb
gosu_extensions-0.2.9 lib/core/initializer_hooks.rb
gosu_extensions-0.2.8 lib/core/initializer_hooks.rb
gosu_extensions-0.2.7 lib/core/initializer_hooks.rb
gosu_extensions-0.2.6 lib/core/initializer_hooks.rb
gosu_extensions-0.2.5 lib/core/initializer_hooks.rb
gosu_extensions-0.2.4 lib/core/initializer_hooks.rb
gosu_extensions-0.2.3 lib/core/initializer_hooks.rb
gosu_extensions-0.2.2 lib/core/initializer_hooks.rb
gosu_extensions-0.2.1 lib/core/initializer_hooks.rb
gosu_extensions-0.2.0 lib/core/initializer_hooks.rb
gosu_extensions-0.1.28 lib/core/initializer_hooks.rb
gosu_extensions-0.1.27 lib/core/initializer_hooks.rb
gosu_extensions-0.1.26 lib/core/initializer_hooks.rb
gosu_extensions-0.1.25 lib/core/initializer_hooks.rb