sts sts - 4 months ago 25
Ruby Question

Validation issue using multiple Proc objects

I have validation with

and problem with it

validates :subcategory, presence: true,
if: {|product| product.detail.blank?} && { |product| != 16 }

My problem is when i have
in second proc my validation fires.

Why is it so? Should it not return
false && true=>false


Others have commented on better ways to implement what you want. I'll just point out the misunderstanding you have.

it should return false because false && true => false

Nope. Actually, it's Proc && Proc => Proc (proc1 && proc2 => proc2). So your first proc is ignored due to how && operator works (this happens at class loading time) and is never called, not even once.