Class: Conditions::InCondition
- Inherits:
-
BaseCondition
- Object
- BaseCondition
- Conditions::InCondition
- Defined in:
- lib/conditions.rb
Overview
Checks if an element (or elements of an array) belong to an array Can be used as an “equals to” condition
Instance Method Summary collapse
- #apply(value) ⇒ true, false
-
#initialize(predicate) ⇒ InCondition
constructor
A new instance of InCondition.
Constructor Details
#initialize(predicate) ⇒ InCondition
Returns a new instance of InCondition.
26 27 28 29 30 |
# File 'lib/conditions.rb', line 26 def initialize(predicate) raise ConditionError, "In condition value must be an Array, not #{predicate.class}" unless predicate.is_a? Array super(predicate) end |
Instance Method Details
#apply(value) ⇒ true, false
36 37 38 39 |
# File 'lib/conditions.rb', line 36 def apply(value) value = [value] unless value.is_a? Array (value & @predicate).any? end |