如何连接条件

时间:2013-07-28 18:54:28

标签: ruby

有没有更优雅的方式在Ruby中编写它?

def tutorial_completed?
  people.any? && projects.any? && invoices.any?
end

2 个答案:

答案 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