merging arrays of hashes
        Posted  
        
            by Ben
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Ben
        
        
        
        Published on 2010-06-01T04:20:40Z
        Indexed on 
            2010/06/01
            4:23 UTC
        
        
        Read the original article
        Hit count: 364
        
I have two arrays of hashes.
Array1 => [{attribute_1 = A, attribute_2 = B}, {attribute_1 = A, attribute_2 = B}]
Array2 => [{attribute_3 = C, attribute_2 = D}, {attribute_3 = C, attribute_4 = D}]
Each hash in the array is holding attributes for an object. In the above example, there are two objects that I'm working with. There are two attributes in each array for each object
How do I merge the two arrays? I am trying to get a single array (there is no way to get a single array from the start because I have to make two different API calls to get these attributes).
DesiredArray => [{attribute_1 = A, attribute_2 = B, attribute_3 = C, attribute_2 = D},
                 {attribute_1 = A, attribute_2 = B, attribute_3 = C, attribute_2 = D}]
I've tried a couple things, including the iteration methods and the merge method, but I've been unable to get the array I need.
© Stack Overflow or respective owner