Join the DZone community and get the full member experience.Join For Free
# If you are treating Arrays like s-expressions, you might want to replace a particular pattern.
Array.class_eval do def replace_pattern(pattern, value) copy = self.dup (0..copy.length).each do |i| if copy[i] == pattern copy[i] = value elsif copy[i].is_a? Array copy[i] = copy[i].replace_pattern(pattern, value) end end copy end end
Opinions expressed by DZone contributors are their own.