From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2002-03-14T17:05:51+09:00 Subject: Re: Method type 'abstract' (Module#abstract) In article <3C9009A9.FC285892@stud.ntnu.no>, Kent Dahl wrote: >Phil Tomson wrote: >> class MyClass >> abstract :some_method >> end >> >> mc = MyClass.new > >Ugh! Some Java/C++ idiom just reared its head in the back of my skull >when seeing this. Since MyClass is abstract, I would expect the call to >new to freak too. (Fail early) Perhaps, but you could redefine it later (classes are always open) or add it as a singleton method so I'm not sure you would want new to fail right away. Actually, I think it's kind of cool that though Ruby doesn't have the concept of abstract methods built-in, you can easily mimick them with less than 10 lines of code. > >Which reminds me: Is there any way of seeing which methods have been >redefined between a super- and subclass? > >SubClass.instance_methods - SuperClass.instance_methods return the new >methods, but how could I get a list of methods that SubClass has >redefined, if that is possible? > Wouldn't you just get the list of SubClass methods that also exist in the SuperClass? Something like (I'm sure there is an easier/more efficient way): redefinedMethods = [] superClassMethods = SuperClass.instance_methods SubClass.instance_methods.each { |subMethod| if superClassMethods.include?(subMethod) redefinedMethods << subMethod end end Actually, come to think of it couldn't you just 'and' the two arrays? redefinedMethods = SuperClass.instance_methods & SubClass.instance_methods Phil