Hi --

On Fri, 15 Jun 2007, Giles Bowkett wrote:

>> kermit.class.instance_methods(false).each{|m|
>> Muppet.instance_eval("remove_method #{m.inspect}")}
>> 
>> Note 1. kermit.methods will return all methods inherited or not.
>> Note 2. remove method is a class method, so it's evaluated in the
>> context of the class object, hence Muppet.instance_eval
>> Note 3: you could alternatively pass symbols for the method names
>> 
>> kermit.class.instance_methods(false).each{|m|
>> Muppet.instance_eval("remove_method :#{m}")}
>
> Muahahaha! That was awesome! Soon the world will quake in fear when I
> put this information to use!
>
> But why doesn't this work?
>
>>> kermit.methods(false).each do |m|
> ?>     Object.instance_eval("remove_method :#{m}")
>>>   end
> => []
>>> kermit.methods
> => 53

kermit.methods(false) will give you kermit's singleton methods:

irb(main):019:0> s = ""
=> ""
irb(main):020:0> def s.x; end
=> nil
irb(main):021:0> s.methods(false)
=> ["x"]

Also, you can't remove these methods from Object because they're not
defined there.  You'd have to do:

   class << s
     remove_method(:x)
   end


David

-- 
* Books:
   RAILS ROUTING (new! http://safari.awprofessional.com/9780321509246)
   RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
     & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)