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 に答える