From: Robert Dober Date: 2007-07-12T21:05:23+09:00 Subject: Re: Abstract methods in ruby ? On 7/12/07, James Edward Gray II wrote: > On Jul 11, 2007, at 5:40 PM, cypher.dp@gmail.com wrote: > > > How do you implement something like the "abstract" keyword in Java ? > > Or: Is there a technique to force a subclass to implement a special > > method ? > > One way is: > > class Parent > def abstract_method > raise NotImplementedError > end > end > > You may just want to skip this step altogether though, since an > exception toss is the default behavior. Hmm, I would say no, you will be caught by #method_missing one day. It would be interesting why you want to do this? For documentation purpose? ( Dumbs up !!) Because you want the feature? (Dumbs down ;) I have not really yet seen a need for an abstract method in Ruby. If you are looking for warnings or errors for subclasses not implementing the abstract method you will be disappointed at Compile Time [which arguabley does not even exist in 1.8] If you are happy with the runtime exception (because you do nice code covering tests ;) James' solution is ideal, anyway you cannot do better ( or worse for must of us;) in Ruby. > > Welcome to the word of dynamic typing. ;) Yes indeed, welcome :) > > James Edward Gray II > > Robert -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck