From: Intransition Date: 2010-10-08T00:02:47+09:00 Subject: Re: "map" a deeply nested structure: Object#deep_map Perhaps what is being sought here is a form of search and replace. class Array def deep_replace(replacement, &match) map do |e| if e.respond_to?(:deep_replace) e.deep_replace(replacement, &match) else match[e] ? replacement : e end end end require 'facets/hash/mash' #[1] class Hash def deep_replace(replacement, &match) mash do |k,v| nk = if k.respond_to?(:deep_replace) k.deep_replace(replacement, &match) else match[k] ? replacement : k end nv = if v.respond_to?(:deep_replace) v.deep_replace(replacement, &match) else match[v] ? replacement : v end [nk, nv] end end Not tested but you get the idea. I'm not 100% sure about handling the key for Hash either, but perhaps an option could toggle that usage on or off. [1]http://blog.thepete.net/2010/02/ruby-facets-mash-method.html