Sha256: 4b0893bee5e22604ce0f977e61db33b3b23473b399235a53b0659d4c6fa58104

Contents?: true

Size: 467 Bytes

Versions: 4

Compression:

Stored size: 467 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 Rango
  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
rango-0.1.0 lib/rango/mixins/hookable.rb
rango-0.0.6 lib/rango/mixins/hookable.rb
rango-0.1.pre lib/rango/mixins/hookable.rb
rango-0.0.4 lib/rango/mixins/hookable.rb