collect funtion to return nested element as an array

Collect function like rails. 
Will be useful in certain cases.