# Remove all class methods via remove\_method

**URL:** <https://www.ruby-forum.com/t/remove-all-class-methods-via-remove-method/159171>\
**Category:** Ruby\
**Created:** [February 1, 2009, 8:35pm UTC](https://www.ruby-forum.com/t/remove-all-class-methods-via-remove-method/159171 "2009-02-01T20:35:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dodeantn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@dodeantn](https://www.ruby-forum.com/u/dodeantn)\
**Post date:** [February 1, 2009, 8:35pm UTC](https://www.ruby-forum.com/t/remove-all-class-methods-via-remove-method/159171/1 "2009-02-01T20:35:41Z")

</div>

Hi,

how do I remove all my class methods like in the following example? –

class Parent  
class \<\< self  
def class\_stuff  
puts “Stuff from my class”  
end  
end  
end

class Child \< Parent

# remove all the class methods;

# should be done automatically with "…methods.each { |m|

remove\_method(m) }"-like construct  
end

Many thanks in advance.

---

<div class="post-metadata">

**Author:** ![dodeantn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@dodeantn](https://www.ruby-forum.com/u/dodeantn)\
**Post date:** [February 2, 2009, 9:21pm UTC](https://www.ruby-forum.com/t/remove-all-class-methods-via-remove-method/159171/2 "2009-02-02T21:21:15Z")

</div>

dodeantn,  
This will do it but I would prefer a better way…

class Parent  
(class \<\< self; self; end).send(:remove\_method, :class\_stuff)  
end

Please remember that with great power comes great responsibility… 🙂  
messing with class methods is a real pain in 1.8 but maybe I am missing  
the boat…

hth

ilan

dodeantn wrote:

> Hi,
> 
> how do I remove all my class methods like in the following example? –
> 
> class Parent  
> class \<\< self  
> def class\_stuff  
> puts “Stuff from my class”  
> end  
> end  
> end
> 
> class Child \< Parent
> 
> # remove all the class methods;
> 
> # should be done automatically with "…methods.each { |m|
> 
> remove\_method(m) }"-like construct  
> end
> 
> Many thanks in advance.
