[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Remove all class methods via remove_method

dodeantn

2/1/2009 7:33:00 PM

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.
1 Answer

Ilan Berci

2/2/2009 8:21:00 PM

0

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.

--
Posted via http://www.ruby-....