Method: Delorean::BaseModule::BaseClass._instance_call

Defined in:
lib/delorean/base.rb

._instance_call(obj, method, args, _e, &block) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/delorean/base.rb', line 210

def self._instance_call(obj, method, args, _e, &block)
  begin
    msg = method.to_sym
  rescue NoMethodError
    raise "bad method #{method}"
  end

  if obj.is_a?(Class) || obj.is_a?(Module)
    matcher = ::Delorean::Ruby.whitelist.class_method_matcher(
      method_name: msg
    )
    klass = obj
  else
    matcher = ::Delorean::Ruby.whitelist.matcher(method_name: msg)
    klass = obj.class
  end

  raise "no such method #{method}" unless matcher

  if matcher.match_to?
    if block
      return(
        _instance_call(obj, matcher.match_to, args, _e, &block)
      )
    else
      return(
        _instance_call(obj, matcher.match_to, args, _e)
      )
    end
  end

  matcher.match!(klass: klass, args: args)

  return obj.public_send(msg, *args) unless block

  obj.public_send(msg, *args, &block)
end