Hi,
most of you probably know/use Ruby F.s
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):
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