Class: Yargi::AndPredicate
- Defined in:
- lib/yargi/predicate.rb
Overview
Conjunction predicate
Constant Summary
Constants inherited from Predicate
Predicate::ALL, Predicate::NONE
Instance Method Summary collapse
-
#&(right) ⇒ Object
Pushes right in the anded array.
-
#===(elm) ⇒ Object
Predicate implementation.
-
#initialize(*anded) ⇒ AndPredicate
constructor
Builds a AND predicate.
-
#inspect ⇒ Object
Helps debugging predicates.
Methods inherited from Predicate
Constructor Details
#initialize(*anded) ⇒ AndPredicate
Builds a AND predicate
159 160 161 162 |
# File 'lib/yargi/predicate.rb', line 159 def initialize(*anded) raise ArgumentError, "Predicates expected" unless anded.all?{|p| Predicate===p} @anded = anded end |
Instance Method Details
#&(right) ⇒ Object
Pushes right in the anded array
170 171 172 173 |
# File 'lib/yargi/predicate.rb', line 170 def &(right) @anded << Predicate.to_predicate(right) self end |
#===(elm) ⇒ Object
Predicate implementation
165 166 167 |
# File 'lib/yargi/predicate.rb', line 165 def ===(elm) @anded.all?{|p| p===elm} end |
#inspect ⇒ Object
Helps debugging predicates
176 177 178 179 180 181 182 183 184 |
# File 'lib/yargi/predicate.rb', line 176 def inspect @anded.inject('') do |memo,p| if memo.empty? p.inspect else "#{memo} and #{p.inspect}" end end end |