def write_attribute(key, value)
      if changed_attributes.key?(key = key.to_s)
        changed_attributes.delete key if changed_attributes[key] == value
      elsif self[key] != value
        changed_attributes[key] = self[key]
      end

      association = self.class.find_association(key)
      if association
        value = fetch_associated(key, value)
      # FIXME: More explicit; less magic.
      elsif value && key.end_with?('_in_cents') && !respond_to?(:currency)
        value = Money.new(value, self, key) unless value.is_a?(Money)
      end

      attributes[key] = value
    end
def write_attribute(key, value)
      if changed_attributes.key?(key = key.to_s)
        changed_attributes.delete key if changed_attributes[key] == value
      elsif self[key] != value
        changed_attributes[key] = self[key]
      end

      association = self.class.find_association(key)
      if association
        value = fetch_associated(key, value)
      # FIXME: More explicit; less magic.
      elsif value && key.end_with?('_in_cents') && !respond_to?(:currency)
        value = Money.new(value, self, key) unless value.is_a?(Money)
      end

      attributes[key] = value
    end
Sets the value of a specified attribute.

 @param key [Symbol, String] The name of the attribute to be set.
 @param value [Object] The value the attribute will be set to.
 @example
   account.write_attribute :first_name, 'Gus'
   account[:company_name] = 'Los Pollos Hermanos'
 @see #read_attribute