有没有更优雅的方式在Ruby中编写它?
def tutorial_completed?
people.any? && projects.any? && invoices.any?
end
答案 0 :(得分:2)
def tutorial_completed?
[people, projects, invoices].all?(&:any?)
end
答案 1 :(得分:1)
我会这样做:
[people,projects,invoices].all? {|i| i.any? }
<强>演示强>
people = [true]
projects = [false]
invoices = [true,12]
[people,projects,invoices].all? {|i| i.any? }
# => false