From: Guido De Rosa Date: 2010-10-06T23:43:46+09:00 Subject: "map" a deeply nested structure: Object#deep_map Hi, most of you probably know/use Ruby Facets http://rubyworks.github.com/facets/ I've recently posted a question on Facets discussion group: http://groups.google.com/group/facets-universal/browse_thread/thread/683215a35f06af36 and I also tried my implementation (which apparently works fine): http://snurl.com/19n6qh class Object def deep_map(&block) if self.respond_to? :each_pair out = {} self.each_pair do |k, v| out[k] = v.deep_map(&block) end return out elsif self.respond_to? :each out = [] self.each do |x| out << x.deep_map(&block) end return out else return block.call(self) end end end Is there room for improvements? Facets author suggested to start a discussion here too. So: what is, in your opinion, the best way to map a deeply nested structure made up of Arrays, Hashes, Array of Hashes etc. etc. ? Thanks, Guido -- Posted via http://www.ruby-forum.com/.