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
-
#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
#object ⇒ Object (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
#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 |