diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-03-17 13:30:17 -0700 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-03-17 13:56:33 -0700 |
commit | b652aa81216f718f27ba257238d4c27dd54863b2 (patch) | |
tree | 6ef65a5e933cdfe1e4e1777c8b4e1a50ebf34515 | |
parent | db2d96a6ba9c8d6d07121853955abe46af350f87 (diff) | |
download | rails-b652aa81216f718f27ba257238d4c27dd54863b2.tar.gz rails-b652aa81216f718f27ba257238d4c27dd54863b2.tar.bz2 rails-b652aa81216f718f27ba257238d4c27dd54863b2.zip |
cleaning up a bunch of method already defined warnings [#4209 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
-rw-r--r-- | activemodel/lib/active_model/attribute_methods.rb | 18 | ||||
-rw-r--r-- | activerecord/lib/active_record/nested_attributes.rb | 3 |
2 files changed, 18 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 588976f1d4..7f2959fcde 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -90,13 +90,20 @@ module ActiveModel # # => 'address_id' def define_attr_method(name, value=nil, &block) sing = singleton_class - sing.send :alias_method, "original_#{name}", name + sing.class_eval <<-eorb, __FILE__, __LINE__ + 1 + if method_defined?(:original_#{name}) + undef :original_#{name} + end + alias_method :original_#{name}, :#{name} + eorb if block_given? sing.send :define_method, name, &block else # use eval instead of a block to work around a memory leak in dev # mode in fcgi - sing.class_eval "def #{name}; #{value.to_s.inspect}; end" + sing.class_eval <<-eorb, __FILE__, __LINE__ + 1 + def #{name}; #{value.to_s.inspect}; end + eorb end end @@ -257,8 +264,13 @@ module ActiveModel if respond_to?(generate_method) send(generate_method, attr_name) else + method_name = matcher.method_name(attr_name) + generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__+1 - def #{matcher.method_name(attr_name)}(*args) + if method_defined?(:#{method_name}) + undef :#{method_name} + end + def #{method_name}(*args) send(:#{matcher.method_missing_target}, '#{attr_name}', *args) end STR diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index bc491c367f..76ec7eb681 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -244,6 +244,9 @@ module ActiveRecord # assign_nested_attributes_for_one_to_one_association(:pirate, attributes) # end class_eval <<-eoruby, __FILE__, __LINE__ + 1 + if method_defined?(:#{association_name}_attributes=) + remove_method(:#{association_name}_attributes=) + end def #{association_name}_attributes=(attributes) assign_nested_attributes_for_#{type}_association(:#{association_name}, attributes) end |