Class: Object

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

“”, “ ”, nil, and 0 are all blank


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_support/core_ext/object_and_class.rb', line 27

def blank?
  if respond_to?(:empty?) && respond_to?(:strip)
    strip.empty?
  elsif respond_to? :empty?
    empty?
  elsif respond_to? :zero?
    zero?
  else
    !self
  end
end

#load(file, *extras) ⇒ Object


192
193
194
195
196
197
# File 'lib/active_support/dependencies.rb', line 192

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

#remove_instance_variables_of(klass) ⇒ Object


9
10
11
12
13
14
15
# File 'lib/active_support/core_ext/object_and_class.rb', line 9

def remove_instance_variables_of(klass)
  ObjectSpace.each_object(Class) do |k|
    if k.to_s == klass
      k.instance_variables.each { |v| k.send(:remove_instance_variable, v) }
    end  
  end   
end

#remove_subclasses_of(*superclasses) ⇒ Object


2
3
4
5
6
7
# File 'lib/active_support/core_ext/object_and_class.rb', line 2

def remove_subclasses_of(*superclasses)
  subclasses_of(*superclasses).each do |subclass|
    subclass.instance_variables.each { |v| subclass.send(:remove_instance_variable, v) }
    Object.send(:remove_const, subclass.to_s) rescue nil
  end
end

#require(file, *extras) ⇒ Object


199
200
201
202
203
204
# File 'lib/active_support/dependencies.rb', line 199

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

#subclasses_of(*superclasses) ⇒ Object


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

def subclasses_of(*superclasses)
  subclasses = []
  ObjectSpace.each_object(Class) do |k|
    next if (k.ancestors & superclasses).empty? || superclasses.include?(k) || k.to_s.include?("::") || subclasses.include?(k)
    subclasses << k
  end
  subclasses
end

#suppress(*exception_classes) ⇒ Object


39
40
41
42
43
44
# File 'lib/active_support/core_ext/object_and_class.rb', line 39

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