表单: RailsNotes
用户: dreamable
创建日期: 2021-04-29 09:15:19 UTC
更新日期: 2021-04-29 09:15:49 UTC
引用:(Table ID 3, Record ID 41)

标题 :
Get all children of children and so on
笔记 :

source

class Customer
  def descendants
    self.children | self.children.map(&:descendants).flatten
  end
end

| is array union.

[ "a", "b", "c" ] | [ "c", "d", "a" ]    #=> [ "a", "b", "c", "d" ]
[ "c", "d", "a" ] | [ "a", "b", "c" ]    #=> [ "c", "d", "a", "b" ]
标签: