Class: ObjectInspector::ObjectInterrogator
- Inherits:
-
Object
- Object
- ObjectInspector::ObjectInterrogator
- 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 ‘kwargs` then they are passed in as well. If not, then any supplied `kwargs` will be ignored.
Instance Attribute Summary collapse
-
#kwargs ⇒ Object
readonly
Returns the value of attribute kwargs.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#call ⇒ String, ...
Whatever type Object##method_name returns.
-
#initialize(object:, method_name:, kwargs: {}) ⇒ ObjectInterrogator
constructor
A new instance of ObjectInterrogator.
Constructor Details
#initialize(object:, method_name:, kwargs: {}) ⇒ ObjectInterrogator
Returns a new instance of ObjectInterrogator.
13 14 15 16 17 |
# File 'lib/object_inspector/object_interrogator.rb', line 13 def initialize(object:, method_name:, kwargs: {}) @object = object @method_name = method_name @kwargs = kwargs end |
Instance Attribute Details
#kwargs ⇒ Object (readonly)
Returns the value of attribute kwargs.
9 10 11 |
# File 'lib/object_inspector/object_interrogator.rb', line 9 def kwargs @kwargs end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
9 10 11 |
# File 'lib/object_inspector/object_interrogator.rb', line 9 def method_name @method_name end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
9 10 11 |
# File 'lib/object_inspector/object_interrogator.rb', line 9 def object @object end |
Instance Method Details
#call ⇒ String, ...
Returns whatever type Object##method_name returns.
23 24 25 26 27 28 29 30 31 |
# File 'lib/object_inspector/object_interrogator.rb', line 23 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 |