Sha256: 9ecb3cad2b031d377aeb8a150932a48fb55b66f9a046d2627f82662d8c45c3d6

Contents?: true

Size: 944 Bytes

Versions: 21

Compression:

Stored size: 944 Bytes

Contents

module RuGUI
  # Adds before/after hooks for initialize method of a class.
  module InitializeHooks
    def self.included(base)
      self.update_initialize_method(base)
    end

    def self.update_initialize_method(base)
      base.class_eval <<-class_eval
        alias :original_initialize :initialize

        def initialize(*args)
          initialize_with_hooks(*args)
        end
      class_eval
    end

    # Calls the original initialize method with before/after hooks.
    def initialize_with_hooks(*args)
      before_initialize
      original_initialize(*args)
      after_initialize
    end

    protected
      # Called before the initialize method. Subclasses can reimplement this in
      # order to have custom behavior.
      def before_initialize
      end

      # Called after the initialize method. Subclasses can reimplement this in
      # order to have custom behavior.
      def after_initialize
      end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
intelitiva-rugui-1.2.0 lib/rugui/initialize_hooks.rb
intelitiva-rugui-1.3.0 lib/rugui/initialize_hooks.rb
intelitiva-rugui-1.3.1 lib/rugui/initialize_hooks.rb
intelitiva-rugui-1.3.2 lib/rugui/initialize_hooks.rb
rugui-2.0.0.beta3 lib/rugui/initialize_hooks.rb
rugui-2.0.0.beta2 lib/rugui/initialize_hooks.rb
rugui-1.6.0 lib/rugui/initialize_hooks.rb
rugui-1.5.4 lib/rugui/initialize_hooks.rb
rugui-1.5.3 lib/rugui/initialize_hooks.rb
rugui-1.5.2 lib/rugui/initialize_hooks.rb
rugui-1.5.0 lib/rugui/initialize_hooks.rb
rugui-1.4.3 lib/rugui/initialize_hooks.rb
rugui-1.4.2 lib/rugui/initialize_hooks.rb
rugui-1.4.0 lib/rugui/initialize_hooks.rb
rugui-1.3.3 lib/rugui/initialize_hooks.rb
rugui-1.3.1 lib/rugui/initialize_hooks.rb
rugui-1.3.2 lib/rugui/initialize_hooks.rb
rugui-1.2.0 lib/rugui/initialize_hooks.rb
rugui-1.2.1 lib/rugui/initialize_hooks.rb
rugui-1.2.2 lib/rugui/initialize_hooks.rb