【发布时间】:2014-04-10 21:13:44
【问题描述】:
此方法的目的是标记用户参加活动。你可以这样理解:如果今天有事件发生,如果用户存在,如果他的状态是订阅或确认,如果这个现有用户尚未签到,则将该用户添加到该事件的用户大批。
对更优雅的解决方案有什么建议吗?
def mark_attendance(user)
if current_event(current_merchant)
if user
if user.status == 'subscribed' || user.status == 'confirmed'
if current_event(current_merchant).users.where(id: user.id) == []
current_event(current_merchant).users << user
end
end
end
end
【问题讨论】:
-
@EliranMalka 我不知道 codereview。我想这是新的,因为它仍处于测试阶段。我上面的问题不是关于解决这个特定问题,而是更多关于如何重构嵌套的 if 语句,因为我经常遇到它们。谢谢你的建议!
标签: if-statement dry