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