0

この文b.followees_by_type("biscuit")は次のようなものを返します。

=> [#<Biscuit _id: 4fdf5aa11d41c829ea000020, _type: "Biscuit", created_at: 2012-06-18 16:43:13 UTC, title: "biscuit biscuit", is_complete: true>, #<Biscuit _id: 4fdf5aa11d41c829ea000021, _type: "Biscuit", created_at: 2012-06-18 17:40:10 UTC, title: "biscuit2 biscuit2", is_complete: true> ] 

1 つまたは複数のビスケットを返すことができます。

@biscuitsインスタンス変数内に、このブロックからの各ループで取得したすべてのビスケットを追加したい:

boards.each do |b| 
  b.followees_by_type("biscuit")
end

どうすればいいですか?

4

1 に答える 1

1

Enumerable#flat_mapを使用します:

@biscuits = boards.flat_map {|b| b.followees_by_type('biscuit') }
于 2012-06-22T17:12:02.533 に答える