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 #kargs then they are passed in as well. If not, then any supplied #kargs will be ignored.
Instance Attribute Summary collapse
-
#kargs ⇒ Object
readonly
Returns the value of attribute kargs.
-
#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 returns.
-
#initialize(object:, method_name:, kargs: {}) ⇒ ObjectInterrogator
constructor
A new instance of ObjectInterrogator.
Constructor Details
#initialize(object:, method_name:, kargs: {}) ⇒ ObjectInterrogator
Returns a new instance of 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
#kargs ⇒ Object (readonly)
Returns the value of attribute kargs.
8 9 10 |
# File 'lib/object_inspector/object_interrogator.rb', line 8 def kargs @kargs end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
8 9 10 |
# File 'lib/object_inspector/object_interrogator.rb', line 8 def method_name @method_name end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
8 9 10 |
# File 'lib/object_inspector/object_interrogator.rb', line 8 def object @object end |
Instance Method Details
#call ⇒ String, ...
Returns whatever type Object##method returns.
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 |