1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Simplify class_method_defined_within

This method was only ever used in one context, where `klass` is `Base`
and `superklass` is `Object`. Since it's private, it shouldn't be used
anywhere else, so we can collapse the whole thing and simplify.
This commit is contained in:
Chris Salzberg 2019-10-21 14:29:00 +09:00
parent 01336b71af
commit 98f2767ac6
No known key found for this signature in database
GPG key ID: C0C7B09832CB1CB1

View file

@ -115,13 +115,11 @@ module ActiveRecord
# A class method is 'dangerous' if it is already (re)defined by Active Record, but
# not by any ancestors. (So 'puts' is not dangerous but 'new' is.)
def dangerous_class_method?(method_name)
RESTRICTED_CLASS_METHODS.include?(method_name.to_s) || class_method_defined_within?(method_name, Base)
end
return true if RESTRICTED_CLASS_METHODS.include?(method_name.to_s)
def class_method_defined_within?(name, klass, superklass = klass.superclass) # :nodoc:
if klass.respond_to?(name, true)
if superklass.respond_to?(name, true)
klass.method(name).owner != superklass.method(name).owner
if Base.respond_to?(method_name, true)
if Object.respond_to?(method_name, true)
Base.method(method_name).owner != Object.method(method_name).owner
else
true
end