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



14
15
16
17
18
# File 'lib/object_inspector/object_interrogator.rb', line 14

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

Instance Attribute Details

#kargsObject (readonly)

Returns the value of attribute kargs.



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

def kargs
  @kargs
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



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

def method_name
  @method_name
end

#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



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

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