Skip to content

Commit

Permalink
cleaning up a bunch of method already defined warnings [#4209 state:r…
Browse files Browse the repository at this point in the history
…esolved]

Signed-off-by: wycats <wycats@gmail.com>
  • Loading branch information
tenderlove authored and wycats committed Mar 17, 2010
1 parent db2d96a commit b652aa8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 15 additions & 3 deletions activemodel/lib/active_model/attribute_methods.rb
Expand Up @@ -90,13 +90,20 @@ module ClassMethods
# # => '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

Expand Down Expand Up @@ -257,8 +264,13 @@ def define_attribute_methods(attr_names)
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
Expand Down
3 changes: 3 additions & 0 deletions activerecord/lib/active_record/nested_attributes.rb
Expand Up @@ -244,6 +244,9 @@ def accepts_nested_attributes_for(*attr_names)
# 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
Expand Down

0 comments on commit b652aa8

Please sign in to comment.