This method takes a hash and returns a new hash without sensitive information. It does not modify the hash passed in.
Is there a more Ruby-like, idiomatic way of doing it?
def sanitize hash
new_hash = hash.dup
protected_keys = [ :password, 'password', :confirmation, 'confirmation' ]
new_hash.each do |k,v|
if protected_keys.include?( k ) && ! v.blank?
new_hash[ k ] = 'xxxxxxxxx'
end
end
new_hash
end
Working in Ruby 1.9.3, Sinatra (not Rails) and not using Active Record.