Skip to content

Instantly share code, notes, and snippets.

@spastorino
Created March 18, 2011 16:53
Show Gist options
  • Select an option

  • Save spastorino/876407 to your computer and use it in GitHub Desktop.

Select an option

Save spastorino/876407 to your computer and use it in GitHub Desktop.
diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb
index 6a593a7..832f2ed 100644
--- a/activerecord/lib/active_record/attribute_methods/write.rb
+++ b/activerecord/lib/active_record/attribute_methods/write.rb
@@ -10,7 +10,9 @@ module ActiveRecord
module ClassMethods
protected
def define_method_attribute=(attr_name)
- generated_attribute_methods.module_eval("def #{attr_name}=(new_value); write_attribute('#{attr_name}', new_value); end", __FILE__, __LINE__)
+ generated_attribute_methods.send(:define_method, "#{attr_name}=") do |new_value|
+ write_attribute(attr_name, new_value)
+ end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment