class ObjectInspector::ObjectInterrogator
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.
Attributes
object[R]
Public Class Methods
new(object:, method_name:, kargs: {})
click to toggle source
# File lib/object_inspector/object_interrogator.rb, line 12 def initialize(object:, method_name:, kargs: {}) @object = object @method_name = method_name @kargs = kargs end
Public Instance Methods
call()
click to toggle source
@return [String, …] whatever type Object#{#method} returns
@raise [ArgumentError] if Object#{#method} has an unexpected method
signature
# 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
Private Instance Methods
call_with_kargs()
click to toggle source
# File lib/object_inspector/object_interrogator.rb, line 34 def call_with_kargs @object.__send__(@method_name, **@kargs) rescue ArgumentError @object.__send__(@method_name) end
object_responds_to_method_name?(include_private: true)
click to toggle source
# File lib/object_inspector/object_interrogator.rb, line 40 def object_responds_to_method_name?(include_private: true) @object.respond_to?(@method_name, include_private) end