class CSVDecision::Matchers::Proc
Composite object for a data cell proc. Note that we do not need it to be comparable. Implemented as an immutable array of 2 or 3 entries for memory compactness and speed. @api private
Public Class Methods
@param type [Symbol] Type of the function value - e.g., :constant or :guard. @param function [Object] Either a lambda function,
or some kind of constant such as an Integer.
@param symbols [nil, Symbol
, Array<Symbol>] The symbol or list of symbols
that the function uses to reference input hash keys (which are always symbolized).
# File lib/csv_decision/matchers.rb, line 20 def initialize(type:, function:, symbols: nil) super() self << type # Function values should always be frozen self << function.freeze # Some function values, such as constants or 0-arity functions, do not reference symbols. self << symbols if symbols freeze end
Public Instance Methods
@param hash [Hash] Input
hash to function call. @param value [Object] Input
value to function call. @return [Object] Value returned from function call.
# File lib/csv_decision/matchers.rb, line 37 def call(hash:, value: nil) func = fetch(1) return func.call(hash) if fetch(0) == :guard # All other procs can take one or two args func.arity == 1 ? func.call(value) : func.call(value, hash) end
@return [Object] Either a lambda function, or some kind of constant such as an Integer.
# File lib/csv_decision/matchers.rb, line 52 def function fetch(1) end
@return [nil, Symbol
, Array<Symbol>] The symbol or list of symbols
that the function uses to reference input hash keys (which are always symbolized).
# File lib/csv_decision/matchers.rb, line 58 def symbols fetch(2, nil) end
@return [Symbol] Type of the function value - e.g., :constant or :guard.
# File lib/csv_decision/matchers.rb, line 47 def type fetch(0) end