Class: CSVDecision::Matchers::Proc Private
- Inherits:
-
Array
- Object
- Array
- CSVDecision::Matchers::Proc
- Defined in:
- lib/csv_decision/matchers.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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.
Instance Method Summary collapse
-
#call(hash:, value: nil) ⇒ Object
private
Value returned from function call.
-
#function ⇒ Object
private
Either a lambda function, or some kind of constant such as an Integer.
-
#initialize(type:, function:, symbols: nil) ⇒ Proc
constructor
private
A new instance of Proc.
-
#symbols ⇒ nil, ...
private
The symbol or list of symbols that the function uses to reference input hash keys (which are always symbolized).
-
#type ⇒ Symbol
private
Type of the function value - e.g., :constant or :guard.
Constructor Details
#initialize(type:, function:, symbols: nil) ⇒ Proc
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Proc.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |
Instance Method Details
#call(hash:, value: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Value returned from function call.
37 38 39 40 41 42 43 44 |
# 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 |
#function ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Either a lambda function, or some kind of constant such as an Integer.
52 53 54 |
# File 'lib/csv_decision/matchers.rb', line 52 def function fetch(1) end |
#symbols ⇒ nil, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The symbol or list of symbols that the function uses to reference input hash keys (which are always symbolized).
58 59 60 |
# File 'lib/csv_decision/matchers.rb', line 58 def symbols fetch(2, nil) end |
#type ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Type of the function value - e.g., :constant or :guard.
47 48 49 |
# File 'lib/csv_decision/matchers.rb', line 47 def type fetch(0) end |