1

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

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

2 回答 2

2
def tutorial_completed?
  [people, projects, invoices].all?(&:any?)
end
于 2013-07-28T18:58:27.860 回答
1

我会做如下:

[people,projects,invoices].all? {|i| i.any? }

演示

 people = [true]
 projects = [false]
 invoices = [true,12]
 [people,projects,invoices].all? {|i| i.any? }
 # => false
于 2013-07-28T18:57:29.307 回答