diff options
author | Tobias Lütke <tobias.luetke@gmail.com> | 2007-10-03 20:47:33 +0000 |
---|---|---|
committer | Tobias Lütke <tobias.luetke@gmail.com> | 2007-10-03 20:47:33 +0000 |
commit | b31aa639e7c8a1f510b8df5e7c57d23440a9a765 (patch) | |
tree | 0752eb7d0e01dca234786232af8d00b329bd60b4 /activerecord | |
parent | 12d740dd57ba5949ba3f0a865285eb52530c86d5 (diff) | |
download | rails-b31aa639e7c8a1f510b8df5e7c57d23440a9a765.tar.gz rails-b31aa639e7c8a1f510b8df5e7c57d23440a9a765.tar.bz2 rails-b31aa639e7c8a1f510b8df5e7c57d23440a9a765.zip |
Allow column accessors to be created even if Kernel. or Object# methods of the same name exist.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7729 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 5f52be1c1d..069983349a 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -58,7 +58,7 @@ module ActiveRecord def define_attribute_methods return if generated_methods? columns_hash.each do |name, column| - unless instance_method_already_defined?(name) + unless instance_method_already_implemented?(name) if self.serialized_attributes[name] define_read_method_for_serialized_attribute(name) else @@ -66,11 +66,11 @@ module ActiveRecord end end - unless instance_method_already_defined?("#{name}=") + unless instance_method_already_implemented?("#{name}=") define_write_method(name.to_sym) end - unless instance_method_already_defined?("#{name}?") + unless instance_method_already_implemented?("#{name}?") define_question_method(name) end end @@ -81,7 +81,18 @@ module ActiveRecord private_method_defined?(method_name) || protected_method_defined?(method_name) end - + + def instance_method_already_implemented?(method_name) + if instance_method_already_defined?(method_name) + # method is defined but maybe its a simple library or kernel method + # which we could simply override: + @@_overrideable_method_names ||= Set.new(Object.instance_methods + Kernel.methods) + @@_overrideable_method_names.include?(method_name) ? false : true + else + false + end + end + alias :define_read_methods :define_attribute_methods |