What is .all?
https://ruby-doc.org/core-2.7.0/Enumerable.html
π€ Situations1: Stop the short circuit evaluation ( && )
Because .valid? has side effect and they want all of forms to evaluate validation, they can't use &&.
@form_a.valid? & @form_b.valid? # π€ evaluate both of valid? but using & is not natual
@form_a.valid? && @form_b.valid? # π€ evaluate only forward if it is false
π Solve it
forms = [@form_a.valid?, @form_b.valid?]
(forms.map(&:valid?)).all?
π€ Situation2: isn't there any errors?
valid = true
users.each do |user|
valid = false unless user.valid?
end
valid
π Solve it
users.map{ |user| user.valid? }.all?
Top comments (0)