How to implement an abstract class in ruby?
- by Chirantan
I know there is no concept of abstract class in ruby. But if at all it needs to be implemented, how to go about it? I tried something like...
class A
def self.new
raise 'Doh! You are trying to instantiate an abstract class!'
end
end
class B < A
...
...
end
But when I try to instantiate B, it is internally going to call A.new which is going to raise the exception.
Also, modules cannot be instantiated but they cannot be inherited too. making the new method private will also not work. Any pointers?