# Remove Nested module constant in ruby

You might have seen this solution.

```ruby
Object.send(:remove_const, :ExampleClass)
```

But what if you want to remove namespaced classes in Ruby. You can use the same method, but instead of `Object` use the parent module where your class is nested.

```ruby
module App
  module ExampleClass
  end 
end 

Object.send(:remove_const, :App::ExampleClass) ### ❌ Does not work!!!!

App.send(:remove_const, :ExampleClass) # ✅ This works
```

Now before removing the const, you can check if the constant is defined or not.

```ruby
if App.const_defined?(:ExampleClass)
  App.send(:remove_const, :ExampleClass)
end 
```

Perfect! 🍄
