find and replace hash values


Hash.class_eval do
  # TODO: unit test this

  def find_and_replace( x, y )
    self.dup.find_and_replace! x, y
  end

  def find_and_replace!( x, y )
    self.each_pair do |k,v|
      if v.is_a?(Hash)
        v.find_and_replace! x, y
      else
        if x.is_a?(Regexp) && v.is_a?(String)
          v.gsub!( x, y )
        else
          v = y if v == x
        end
        self[k] = v
      end
    end
  end

end

actionmailer ActionView ActiveRecord activesupport agile ajax alphadecimal audio autotest BDD blocks capistrano ssh ruby console controller css dashboard widget delegate dog puppy naming name DRM email obfuscation exceptions factories factories-and-workers factory pattern filemerge find and replace finder fink fixtures fun functional testing gem gems git google maps haml hash helper helpers imagemagick install Intertrust irb javascript jquery jrails logo macro math meetup model openssl OS X patch Pioneer Electronics plugin polymorphism project management prototype.js rails rails gotcha rails,patch,validations railsconf rake rmagick RSA encryption ruby ruby on rails script scrum scrum lessons rails scrumninja shoulda subversion SyncTV TDD testing textmate tips tricks unique hashes unix shell validation view yaml zebra stripes