class Porridge::SendExtractor
{SendExtractor} is an extractor that retrieves a value from an object by simply calling a predefined method on it.
Attributes
method_name[R]
The name of the method to call when extracting the value. @return [String]
Public Class Methods
new(method_name)
click to toggle source
Creates a new instance of {SendExtractor} with the given method name. @param method_name
[String, Symbol] the name of the method to call when extracting the value.
Calls superclass method
# File lib/porridge/send_extractor.rb, line 8 def initialize(method_name) @method_name = method_name.to_s super() end
Public Instance Methods
call(object, _options)
click to toggle source
Extracts the value from the given object by sending the method name ({#method_name}) to it. @param object the object from which to retrieve the value. @param _options [Hash] a hash of “options,” which may be application-specific. These options are ignored. @return the extracted value, as returned from the sent method.
# File lib/porridge/send_extractor.rb, line 17 def call(object, _options) object.respond_to?(method_name) ? object.send(method_name) : nil end