有没有更优雅的方式在 Ruby 中编写它?
def tutorial_completed?
people.any? && projects.any? && invoices.any?
end
有没有更优雅的方式在 Ruby 中编写它?
def tutorial_completed?
people.any? && projects.any? && invoices.any?
end
def tutorial_completed?
[people, projects, invoices].all?(&:any?)
end
我会做如下:
[people,projects,invoices].all? {|i| i.any? }
演示
people = [true]
projects = [false]
invoices = [true,12]
[people,projects,invoices].all? {|i| i.any? }
# => false