lib/guard/hook.rb
# When +event+ is a Symbol, {#hook} will generate a hook name
# by concatenating the method name from where {#hook} is called
# with the given Symbol.
#
# @example Add a hook with a Symbol
#   def run_all
#     hook :foo
#   end
#
# Here, when {Guard::Guard#run_all} is called, {#hook} will notify callbacks
# registered for the "run_all_foo" event.
#
# When +event+ is a String, {#hook} will directly turn the String
# into a Symbol.
#
# @example Add a hook with a String
#   def run_all
#     hook "foo_bar"
#   end
#
# When {Guard::Guard#run_all} is called, {#hook} will notify callbacks
# registered for the "foo_bar" event.
#
# @param [Symbol, String] event the name of the Guard event
# @param [Array] args the parameters are passed as is to the callbacks registered for the given event.
#
When +event+ is a Symbol, {#hook} will generate a hook name
by concatenating the method name from where {#hook} is called
with the given Symbol.
When + event + is a Symbol { #hook } will generate a hook name by concatenating the method name from where { #hook } is called with the given Symbol .
def hook(event, *args)
        hook_name = if event.is_a? Symbol
                      calling_method = caller[0][/`([^']*)'/, 1]
                      "#{ calling_method }_#{ event }"
                    else
                      event
                    end.to_sym
        UI.debug "Hook :#{ hook_name } executed for #{ self.class }"
        Hook.notify(self.class, hook_name, *args)
      end
def hook ( event , * args ) hook_name = if event . is_a? Symbol calling_method = caller [ 0 ] [ / `([^']*)' / , 1 ] "#{ calling_method }_#{ event }" else event end . to_sym UI . debug "Hook :#{ hook_name } executed for #{ self.class }" Hook . notify ( self . class , hook_name , * args ) end
When +event+ is a Symbol, {#hook} will generate a hook name
by concatenating the method name from where {#hook} is called
with the given Symbol.
When + event + is a Symbol { #hook } will generate a hook name by concatenating the method name from where { #hook } is called with the given Symbol .
event
args
args the parameters are passed as is to the callbacks registered for the given event.
args the parameters are passed as is to the callbacks registered for the given event .
example
Add a hook with a Symbol def run_all hook :foo end Here, when {Guard::Guard#run_all} is called, {#hook} will notify callbacks registered for the "run_all_foo" event. When +event+ is a String, {#hook} will directly turn the String into a Symbol.
Add a hook with a Symbol def run_all hook : foo end Here when { Guard :: Guard#run_all } is called { #hook } will notify callbacks registered for the " run_all_foo " event . When + event + is a String { #hook } will directly turn the String into a Symbol .
example
Add a hook with a String def run_all hook "foo_bar" end When {Guard::Guard#run_all} is called, {#hook} will notify callbacks registered for the "foo_bar" event.
Add a hook with a String def run_all hook " foo_bar " end When { Guard :: Guard#run_all } is called { #hook } will notify callbacks registered for the " foo_bar " event .