Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/active_record/support/dependencies.rb,
lib/active_record/support/core_ext/object_and_class.rb
Overview
:nodoc:
Class Method Summary collapse
-
.const_missing(class_id) ⇒ Object
Use const_missing to autoload associations so we don’t have to require_association when using single-table inheritance.
Instance Method Summary collapse
Class Method Details
.const_missing(class_id) ⇒ Object
Use const_missing to autoload associations so we don’t have to require_association when using single-table inheritance.
54 55 56 57 58 59 60 61 |
# File 'lib/active_record/support/dependencies.rb', line 54 def const_missing(class_id) begin require_or_load(class_id.to_s.demodulize.underscore) if Object.const_defined?(class_id) then return Object.const_get(class_id) else raise LoadError end rescue LoadError raise NameError, "uninitialized constant #{class_id}" end end |
Instance Method Details
#remove_subclasses_of(superclass) ⇒ Object
2 3 4 |
# File 'lib/active_record/support/core_ext/object_and_class.rb', line 2 def remove_subclasses_of(superclass) subclasses_of(superclass).each { |subclass| Object.send(:remove_const, subclass) rescue nil } end |
#subclasses_of(superclass) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/active_record/support/core_ext/object_and_class.rb', line 6 def subclasses_of(superclass) subclasses = [] ObjectSpace.each_object(Class) do |k| next if !k.ancestors.include?(superclass) || superclass == k || k.to_s.include?("::") || subclasses.include?(k.to_s) subclasses << k.to_s end subclasses end |