这是在声明上施加条件的有效方法吗?前几天在一行中使用时,我无法使用多个&&&&&&&'s或||'
@sales_opportunities << auction unless auction.company == current_user || !(auction.bids & current_user.bids).empty? || !auction.condition.include?(part.condition)
答案 0 :(得分:4)
一些想法:
答案 1 :(得分:2)
@CaptainChaos和@PascalBetz说的是什么。至少,将该条件的一部分提取到具有描述性名称的本地变量。像这样:
insider_user = auction.company == current_user
user_placed_bids = (auction.bids & current_user.bids).present?
part_matches = auction.condition.include?(part.condition)
@sales_opportunities << auction unless insider_user || user_placed_bids || !part_matches
现在这看起来更易于管理,嘿?