instance method
instance_method_already_implemented?
Ruby on Rails 4.1.16
Since v2.2.3Signature
instance_method_already_implemented?(method_name)
Raises a ActiveRecord::DangerousAttributeError exception when an Active Record method is defined in the model, otherwise false.
class Person < ActiveRecord::Base def save 'already defined by Active Record' end end Person.instance_method_already_implemented?(:save) # => ActiveRecord::DangerousAttributeError: save is defined by ActiveRecord Person.instance_method_already_implemented?(:name) # => false
Parameters
-
method_namereq
Source
# File activerecord/lib/active_record/attribute_methods.rb, line 106
def instance_method_already_implemented?(method_name)
if dangerous_attribute_method?(method_name)
raise DangerousAttributeError, "#{method_name} is defined by Active Record. Check to make sure that you don't have an attribute or method with the same name."
end
if superclass == Base
super
else
# If ThisClass < ... < SomeSuperClass < ... < Base and SomeSuperClass
# defines its own attribute method, then we don't want to overwrite that.
defined = method_defined_within?(method_name, superclass, Base) &&
! superclass.instance_method(method_name).owner.is_a?(GeneratedAttributeMethods)
defined || super
end
end
Defined in activerecord/lib/active_record/attribute_methods.rb line 106
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::AttributeMethods::ClassMethods