From: Robert Date: 2003-05-01T02:35:23+09:00 Subject: Re: Self modifying systems question "Sten Kvamme" schrieb im Newsbeitrag news:3DF19A9C-7B0D-11D7-93CD-003065DC4D52@as4-2-8.an.g.bonet.se... > Hello, > > Self modifying code is a well known technology. Has anyone done this in > Ruby? What I'm seeking for is examples of software that adds to > itself (methods and variables) in runtime. > > I understand from reading the Ruby documentation that it is easy > to add a method programmatically to a running object instance, but > is it also possible to maintain changes (persistance) after system > halts? I think not directly. I guess you couls store a map from method name to method code and recreate the methods after loading. class Foo def initialize() @dynamic_methods = [] end # some code that adds to @dynamic_methods def after_load() @dynamic_methods.each do |code| # code is something like "def foo(); puts 'foo'; end" instance_eval code end end end Regards robert