From: Kent Sibilev Date: 2005-07-20T02:31:04+09:00 Subject: Re: Removing Instance Methods Yeah, you're right. I should have tested it first before posting :) Kent. On 7/19/05, ts wrote: > >>>>> "B" == Brian Takita writes: > > B> def custom_remove_method(obj, sym) > B> obj.instance_variable_set(:@symbol_to_be_removed, obj) > B> class << obj > B> remove_method(@symbol_to_be_removed) > B> remove_instance_variable(:@symbol_to_be_removed) > B> end > B> end > > moulon% cat b.rb > #!/usr/bin/ruby > def custom_remove_method(obj, sym) > class << obj; self end.send(:remove_method, sym) > end > class << a = [] > def un > puts 1 > end > end > a.un > custom_remove_method(a, :un) > a.un > moulon% > > moulon% ./b.rb > 1 > ./b.rb:12: undefined method `un' for []:Array (NoMethodError) > moulon% > > > > Guy Decoux > >