如何简化以下if语句以删除重复?
if user.name == "john" && user.age > 10 or user.name == "wendy" && user.age > 10 or user.name == "mary" && user.age > 10
谢谢!
答案 0 :(得分:6)
if ['john', 'wendy', 'mary'].include?(user.name) && user.age > 10
答案 1 :(得分:0)
require 'set'
target_names = Set.new ["john", "wendy", "mary"]
if target_names.include? user.name and user.age > 10 ...