Class: ObjectInspector::ObjectInterrogator

Inherits:
Object
  • Object
show all
Defined in:
lib/object_inspector/object_interrogator.rb

Overview

ObjectInspector::ObjectInterrogator collaborates with @object to return Object#@method_name if @object responds to the method.

If Object#@method_name accepts the supplied @kargs then they are passed in as well. If not, then any supplied @kargs will be ignored.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object:, method_name:, kargs: {}) ⇒ ObjectInterrogator



12
13
14
15
16
# File 'lib/object_inspector/object_interrogator.rb', line 12

def initialize(object:, method_name:, kargs: {})
  @object = object
  @method_name = method_name
  @kargs = kargs
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



10
11
12
# File 'lib/object_inspector/object_interrogator.rb', line 10

def object
  @object
end

Instance Method Details

#callString, ...

Returns whatever type Object##method returns.

Raises:

  • (ArgumentError)

    if Object##method has an unexpected method signature



22
23
24
25
26
27
28
29
30
# File 'lib/object_inspector/object_interrogator.rb', line 22

def call
  return unless object_responds_to_method_name?

  if @object.method(@method_name).arity != 0
    call_with_kargs
  else
    @object.__send__(@method_name)
  end
end