Class: Object

Inherits:
BasicObject
Defined in:
lib/active_support/dependencies.rb,
lib/active_support/core_ext/object_and_class.rb

Overview

:nodoc:

Class Method Summary collapse

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.



174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/active_support/dependencies.rb', line 174

def const_missing(class_id)
  if Object.const_defined?(:Controllers) and Object::Controllers.const_available?(class_id)
    return Object::Controllers.const_get(class_id)
  end

  begin
    require_dependency(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 => e
    raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e)
  end
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
# File 'lib/active_support/core_ext/object_and_class.rb', line 15

def blank?
  if respond_to? :empty?
    empty?
  elsif respond_to? :zero?
    zero?
  else
    !self
  end
end

#load(file, *extras) ⇒ Object



188
189
190
191
192
193
194
# File 'lib/active_support/dependencies.rb', line 188

def load(file, *extras)
  begin super(file, *extras)
  rescue Object => exception
    exception.blame_file! file
    raise
  end
end

#remove_subclasses_of(superclass) ⇒ Object



2
3
4
# File 'lib/active_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

#require(file, *extras) ⇒ Object



196
197
198
199
200
201
202
# File 'lib/active_support/dependencies.rb', line 196

def require(file, *extras)
  begin super(file, *extras)
  rescue Object => exception
    exception.blame_file! file
    raise
  end
end

#subclasses_of(superclass) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/active_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

#suppress(*exception_classes) ⇒ Object



25
26
27
28
29
30
# File 'lib/active_support/core_ext/object_and_class.rb', line 25

def suppress(*exception_classes)
  begin yield
  rescue Exception => e
    raise unless exception_classes.any? {|cls| e.kind_of? cls}
  end
end