From: mike lupo Date: 2012-02-25T08:41:11+09:00 Subject: How do I recursively traverse a data structure containing a mix of types? For starters, I'm a total ruby noob who needs to be able to structure the input data in such a way that it can be accessed & structured sensibly. I found an example on here that I've modified to the best of my ability..but it does not do what I want. The attached input file contains a real-life piece of data. Here is the recursive function: I appreciate anyone who'd take a stab at this. def strip_hash_values(hash) #hash.each_value do |v| hash.each do |v| puts " strip_hash_values -- >" case v when String then puts "STRING #{v}" #v.strip! puts "<--strip_hash_values" return v #when Array then strip_array_values(v)# i.strip!} when Array then v.each {|i| #puts #Z"ARRAY value: #{i}" strip_hash_values(v)} # i.strip!} when Hash then strip_hash_values(v) when Integer then puts "Integer #{v}" puts "<--strip_hash_values" return v else raise ArgumentError, "Unhandled type #{v.class}" end end end Attachments: http://www.ruby-forum.com/attachment/7097/SampleInput.txt -- Posted via http://www.ruby-forum.com/.