tags:

views:

55

answers:

1
parent = ["A","B","C",["a","b", "c", "d"], "D"]

parent.each do |children|

if children.is_a?

children.flatten # how do i insert it back to parent
# so that this loop can continue looping through the remainder
#including the newly flattened children(a,b,c,d)

end

end

The question is, once an array is discovered, i flatten it, and need it to be inserted it to the original parent array, so that A,B,C,a,b,c,d,D will be looped once.

+1  A: 

From the description it seems that you would be able to do

parent.flatten.each do |child|
end
Rickard
When you say "need it to be inserted it to the original parent array" you mean you want the flattened contents to overwrite the original contents, modify the iterator to read:`parent.flatten!.each do |child|...end`
bta
yes that makes sense. as flatten! overwrites itself. flatten produces new array. thank you.
gweg