title: Ruby on Rails overriding values in the changes hash
body: <p>I'm trying to add a before_validation hook that will clean up extraneous white space.  As part of that I wanted to also set any blank string values back to nil.  The reason for this being to prevent users from entering empty spaces into a required field in an attempt to bypass it.  </p>
  
  <p>The below is how I have tried to do this.  The changes[x][1].strip! line works as I would expect and gives me back a blanks line.  What I found surprising though is that where I attempt to set changes[x][1] = nil, the value of changes[x][1] remains unchanged.  Stepping through some debugging tests I found that not only did that fail, but any attempt to set changes[x][1] to ANY value fails to actually update the array!</p>
  
  <p>I would love to hear what I'm doing wrong here, and how I can fix it.  Thanks so much!</p>
  
  <pre><code>def strip_whitespace
    changes.keys.each do |x|
      if changes[x][1].respond_to?(:strip!)
        changes[x][1] = nil if changes[x][1].blank?
        changes[x][1].strip!
      end
    end
  end
  </code></pre>