Class: ObjectInspector::InterrogateObject
- Inherits:
-
Object
- Object
- ObjectInspector::InterrogateObject
- 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
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
-
#call ⇒ String, ...
Whatever type Object##method_name returns.
-
#initialize(object, method_name:, kwargs: {}) ⇒ InterrogateObject
constructor
A new instance of InterrogateObject.
Constructor Details
#initialize(object, method_name:, kwargs: {}) ⇒ InterrogateObject
Returns a new instance of InterrogateObject.
15 16 17 18 19 |
# File 'lib/object_inspector/interrogate_object.rb', line 15 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.
11 12 13 |
# File 'lib/object_inspector/interrogate_object.rb', line 11 def kwargs @kwargs end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
11 12 13 |
# File 'lib/object_inspector/interrogate_object.rb', line 11 def method_name @method_name end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
11 12 13 |
# File 'lib/object_inspector/interrogate_object.rb', line 11 def object @object end |
Class Method Details
.call ⇒ Object
9 |
# File 'lib/object_inspector/interrogate_object.rb', line 9 def self.call(...) = new(...).call |
Instance Method Details
#call ⇒ String, ...
Returns Whatever type Object##method_name returns.
25 26 27 28 29 30 31 32 33 |
# File 'lib/object_inspector/interrogate_object.rb', line 25 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 |