From: David Alan Black Date: 2001-03-07T01:13:40+09:00 Subject: [ruby-talk:12152] Re: hooking/wrapping all of a classes methods Hi -- On Wed, 7 Mar 2001, Brian F. Feldman wrote: > David Alan Black wrote: > >[skipping non-code... :)] > > class Thing > > def mone > > puts "hi" > > end > > > > def mtwo(a) > > puts "bye" > > end > > > > superclass.instance_methods - instance_methods .each do |m| > > For what it's worth, this will only "seem to" work. It won't give you an > error because the #each method will return the original object and you can > of course subtract to Arrays like that. It won't actually pass a modified > Array to the #each call though, only "instance_methods" itself. Right y'are. And it's all backwards anyway. And Thing's superclass doesn't have any instance methods. And I've abandoned this project :-) But just for closure, how about: class Thing < String def thing # Note subtle switch of operand order here :-) for m in Thing.instance_methods - Thing.superclass.instance_methods puts m.to_s end end end Thing.new("").thing => thing David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav