Method: Extlib::Hook::ClassMethods#inline_call

Defined in:
lib/extlib/hook.rb

#inline_call(method_info, scope) ⇒ Object

Returns ruby code that will invoke the hook. It checks the arity of the hook method and passes arguments accordingly.



270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/extlib/hook.rb', line 270

def inline_call(method_info, scope)
  Extlib::Hook::ClassMethods.hook_scopes << method_info[:from]
  name = method_info[:name]

  if scope == :instance
    args = method_defined?(name) && instance_method(name).arity != 0 ? '*args' : ''
    %(#{name}(#{args}) if self.class <= Extlib::Hook::ClassMethods.object_by_id(#{method_info[:from].object_id}))
  else
    args = respond_to?(name) && method(name).arity != 0 ? '*args' : ''
    %(#{name}(#{args}) if self <= Extlib::Hook::ClassMethods.object_by_id(#{method_info[:from].object_id}))
  end
end