From: "David A. Black" Date: 2005-08-12T00:57:12+09:00 Subject: Re: Dynamically changing class methods Hi -- On Fri, 12 Aug 2005, henrikbrink wrote: > Hello! > > Im making an application that loads and uses the methods of a class > dynamically. The class can then be altered while the application is > running, and the application loads the file containing the class every > time it is needed. > > The strange thing is: It works fine when i add a method to the class. > The new method shows up. But if i remove a method, it acts as if it was > still there. How can that be? > > Here's the code used to get the methods: > > load "#{file}.rb" > myclass = Object.const_get "MyClass" > myclass_inst = myclass.new > methods = myclass_inst.methods If you do this: class MyClass def some_method # ... end end and then, later, do this: class MyClass end (i.e., don't define some_method), some_method is still there. The effects of opening a class multiple times are cumulative. This is the case whether it's all in one file or in multiple files, or even in the same file loaded multiple times. If you want to remove a method, you have to use remove_method or under_method (which are slightly different from each other; see ri or other docs). > If I am not clear enough, please ask. Same here :-) David -- David A. Black dblack@wobblini.net