Class: ObjectInspector::InterrogateObject

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

Overview

Collaborates with #object to return #object##method_name if #object responds to #method_name.

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, method_name:, kwargs: {}) ⇒ InterrogateObject

Returns a new instance of InterrogateObject.



16
17
18
19
20
# File 'lib/object_inspector/interrogate_object.rb', line 16

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

Instance Attribute Details

#kwargsObject (readonly)

Returns the value of attribute kwargs.



12
13
14
# File 'lib/object_inspector/interrogate_object.rb', line 12

def kwargs
  @kwargs
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



12
13
14
# File 'lib/object_inspector/interrogate_object.rb', line 12

def method_name
  @method_name
end

#objectObject (readonly)

Returns the value of attribute object.



12
13
14
# File 'lib/object_inspector/interrogate_object.rb', line 12

def object
  @object
end

Class Method Details

.callObject?

Returns The result of calling #method_name on #object, or nil if #object does not respond to #method_name.

Returns:



10
# File 'lib/object_inspector/interrogate_object.rb', line 10

def self.call(...) = new(...).call

Instance Method Details

#callObject?

Returns The result of calling #method_name on #object, or nil if #object does not respond to #method_name.

Returns:

Raises:



27
28
29
30
31
32
33
34
35
# File 'lib/object_inspector/interrogate_object.rb', line 27

def call
  return unless object_responds_to_method_name?

  if object.method(method_name).arity.zero?
    object.__send__(method_name)
  else
    call_with_kwargs
  end
end