ruby on rails - How to avoid short-circuit evaluation on -


I am working with Ruby on Rails and want to validate two separate models:

  If (model1.valid? & Amp; amp; amp; model 2. valid?) ... end  

However, "& amp; operator short circuit evaluation (I.e. it evaluates "model2.valid?" If only "model1.valid?" Is true), which prevents models from executing 2. Valid if model 1 is not valid.

is there "& amp; Amp; & Amp; Which will not use short circuit evaluation? I need to evaluate two prices.

Try it out:

  ([Model 1, Model 2] .map (and: valid?)) All?  

If both are valid, then this truth will return, and make errors on both instances.


Comments