Module: Ohai::Mixin::ConstantHelper

Included in:
System
Defined in:
lib/ohai/mixin/constant_helper.rb

Instance Method Summary collapse

Instance Method Details

#recursive_remove_constants(object) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/ohai/mixin/constant_helper.rb', line 34

def recursive_remove_constants(object)
  if object.respond_to?(:constants)
    object.constants.each do |const|
      next unless strict_const_defined?(object, const)

      recursive_remove_constants(object.const_get(const))
      object.send(:remove_const, const)
    end
  end
end

#remove_constantsObject



25
26
27
28
29
30
31
32
# File 'lib/ohai/mixin/constant_helper.rb', line 25

def remove_constants
  new_object_constants = Object.constants - @object_pristine.constants - [ :SortedSet ]
  new_object_constants.each do |constant|
    Object.send(:remove_const, constant) unless Object.const_get(constant).is_a?(Module)
  end

  recursive_remove_constants(Ohai::NamedPlugin)
end

#strict_const_defined?(object, const) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
# File 'lib/ohai/mixin/constant_helper.rb', line 45

def strict_const_defined?(object, const)
  if object.method(:const_defined?).arity == 1
    object.const_defined?(const)
  else
    object.const_defined?(const, false)
  end
end