Module: Cant::Folds

Defined in:
lib/cant/engine.rb

Class Method Summary collapse

Class Method Details

.first_rule_that_predicates(rules, _receiver, *args) ⇒ Object

first rule that predicates to true, all args are carried to closure this strategy does not use the receiver argument, and evaluate each predicate with the binding of its creation



172
173
174
# File 'lib/cant/engine.rb', line 172

def first_rule_that_predicates(rules, _receiver, *args)
  rules.find {|rule| rule.predicate?(*args)}
end

.first_rule_that_predicates_in_receiver(rules, receiver, *args) ⇒ Object

strategy that evals block in receiver context closure is rebound to receiver (acting as a function)



177
178
179
180
181
# File 'lib/cant/engine.rb', line 177

def first_rule_that_predicates_in_receiver(rules, receiver, *args)
  rules.find do |rule|
    receiver.instance_exec(*args, &(rule.predicate))
  end
end