1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Use ancestors instead of manually walking the superclass chain.

This commit is contained in:
Tobias Crawley 2010-04-22 13:32:23 -04:00
parent d60f1d8719
commit 1e28a85396

View file

@ -18,7 +18,7 @@ module AwesomePrintActiveRecord
if object.is_a?(ActiveRecord::Base) if object.is_a?(ActiveRecord::Base)
printable = :active_record_instance printable = :active_record_instance
end end
elsif printable == :class and class_inherits_from(object, ActiveRecord::Base) elsif printable == :class and object.ancestors.include?(ActiveRecord::Base)
printable = :active_record_class printable = :active_record_class
end end
printable printable
@ -48,13 +48,6 @@ module AwesomePrintActiveRecord
end end
end end
private
def class_inherits_from(klass, parent_class)
while klass do
return true if klass == parent_class
klass = klass.superclass
end
end
end end
AwesomePrint.send(:include, AwesomePrintActiveRecord) AwesomePrint.send(:include, AwesomePrintActiveRecord)