1
my_hash = Hash.new
my_hash[:children] = Array.new
然後,我有一個自稱一些時間,每次寫入孩子的函數
my_hash[:children] = my_replicating_function(some_values)
怎麼辦我寫入時不覆蓋已寫入的數據?
這是整個功能是什麼樣子
def self.build_structure(candidates, reports_id)
structure = Array.new
candidates.each do |candidate, index|
if candidate.reports_to == reports_id
structure = candidate
structure[:children] = Array.new
structure[:children] = build_structure(candidates, candidate.candidate_id)
end
end
structure
end