Traversing an object / array?


#1

This is a very basic question but I cannot find the ‘right’ answer.

What is the best way to traverse an object / array with ROR.

I need to look at the structure of some of the objects/ arrays but not
sure how to go about it.

I appreciate your assistance.

Thanks
Frank


#2

On 7/02/2006, at 10:36 AM, softwareengineer 99 wrote:

This is a very basic question but I cannot find the ‘right’ answer.

What is the best way to traverse an object / array with ROR.

I need to look at the structure of some of the objects/ arrays but
not sure how to go about it.

For an array:

array.each do |item|
// stuff with item
end

An object is trickier, they’re not supposed to be traversed like an
array. Check out ruby-doc.org, the 1.8 reference documentation, the
interesting methods are in the Object and Module classes