Reputation: 6475
I do the following
my_hash = Hash.new
my_hash[:children] = Array.new
I then have a function that calls itself a number of time each time writing to children
my_hash[:children] = my_replicating_function(some_values)
How do I write without overwriting data that is already written ?
This is what the entire function looks like
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
Upvotes: 1
Views: 184
Reputation: 4113
Maybe this:
structure[:children] << build_structure(candidates, candidate.candidate_id)
Upvotes: 3
Reputation: 24617
structure[:children] << build_structure(candidates, candidate.candidate_id)
Upvotes: 2