Sha256: 86adbdf41e8468a4335df35adca38b72b330f1f167636c136b1d83fe8b1c34bd

Contents?: true

Size: 470 Bytes

Versions: 4

Compression:

Stored size: 470 Bytes

Contents

# encoding: utf-8

# class Test
#   extend Rango::Hookable
#   install_hook do |instance|
#     p instance
#   end
#
#   def initialize
#     p self
#   end
# end
#
# Test.new

module RubyExts
  module Hookable
    def new(*args)
      instance = super(*args)
      self.hooks.each { |hook| hook.call(instance) }
      return instance
    end

    def hooks
      @hooks ||= Array.new
    end

    def install_hook(&block)
      self.hooks.push(block)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubyexts-0.3.pre lib/rubyexts/mixins/hookable.rb
rubyexts-0.0.2.1 lib/rubyexts/mixins/hookable.rb
rubyexts-0.0.2 lib/rubyexts/mixins/hookable.rb
rubyexts-0.1.pre lib/rubyexts/mixins/hookable.rb