Module: RubyHooks::InstanceHooks

Defined in:
lib/ruby-hooks/instance_hooks.rb

Overview

Helper to add multiple instance hooks

Instance Method Summary collapse

Instance Method Details

#define_hook(name, options = {}) ⇒ Method or Symbol

define instance hook method, it gives easy acces to Hook and it’s methods

Parameters:

  • name (Symbol)

    name of the hook handling method to define

  • options (Hash) (defaults to: {})

    optional settigns for hook

Options Hash (options):

  • :extends (Module)
    • the module to extend hook instance

Returns:

  • (Method or Symbol)

    exactly what method definition would return



19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby-hooks/instance_hooks.rb', line 19

def define_hook(name, options = {})
  define_method(name) do
    if hook = instance_variable_get(:"@#{name}")
    then return hook
    end
    hook = RubyHooks::Hook.new(options)
    instance_variable_set(:"@#{name}", hook)
    hook
  end
end