Traversal is best done with recursion. There are three cases:
The first case is the easy one: just return x.inspect.
If x is an array, call label(e) for each element e of x and form a string from the results.
If x is a hash, call label(key) and label(value) for each key/value pair and form a string from the results. Use x.each {|k,v| ... } to iterate through the key/value pairs.