Class: RHook::Invocation

Inherits:
Struct
  • Object
show all
Defined in:
lib/rhook.rb

Overview

The object contains the invocation information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsArray<Object>

The arguments given to the method invocation.

Returns:

  • (Array<Object>)

    the current value of args



282
283
284
# File 'lib/rhook.rb', line 282

def args
  @args
end

#blockProc

The block given to the method invocation

Returns:

  • (Proc)

    the current value of block



282
283
284
# File 'lib/rhook.rb', line 282

def block
  @block
end

#hintHash

Hint data given by RHookService#does / RHookService#to.

Returns:

  • (Hash)

    the current value of hint



282
283
284
# File 'lib/rhook.rb', line 282

def hint
  @hint
end

#hooksArray<Hook> (readonly)

(Internally used) The applied hooks on this invocation.

Returns:

  • (Array<Hook>)

    the current value of hooks



282
283
284
# File 'lib/rhook.rb', line 282

def hooks
  @hooks
end

#receiverObject (readonly)

The receiver object of this method invocation.

Returns:

  • (Object)

    the current value of receiver



282
283
284
# File 'lib/rhook.rb', line 282

def receiver
  @receiver
end

#returnedObject (readonly)

The returned value by the method invocation. (Don’t set this. To change it, just return by the alternative value from the hook procedure.)

Returns:

  • (Object)

    the current value of returned



282
283
284
# File 'lib/rhook.rb', line 282

def returned
  @returned
end

#targetObject (readonly)

The target object that the hook is applied. (Usually same to #receiver)

Returns:

  • (Object)

    the current value of target



282
283
284
# File 'lib/rhook.rb', line 282

def target
  @target
end

#target_procProc

(Internally used) The procedure to execute the target method/procedure.

Returns:

  • (Proc)

    the current value of target_proc



282
283
284
# File 'lib/rhook.rb', line 282

def target_proc
  @target_proc
end

Instance Method Details

#proceedObject Also known as: call

Proceed to execute the next one on hooks-chain. If no more hooks, execute the target method/procedure.

Returns:

  • The returned value from the target method/procedure. (may changed by hook)



290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/rhook.rb', line 290

def proceed
  hook = hooks[@hook_index]
  # -- If no more hook was found, calls target procedure and return
  hook or return self.returned = target_proc.call(*args, &block)
  # -- Set hook pointer to next, then call next hook
  @hook_index += 1
  begin
    self.returned = hook.call(self)
  ensure
    @hook_index -= 1
  end
end