From: "NAKAMURA, Hiroshi" Date: 2000-06-20T21:17:28+09:00 Subject: [ruby-talk:03556] Re: Ruby classes and inheritance Hi, > From: dave@thomases.com [mailto:dave@thomases.com] > Sent: Tuesday, June 20, 2000 10:30 AM > However, it's fun to think about implementing abstract base classes, > just to see how it could be handled. It is very fun. I used to consider how can I show the interface of my library explicitly. % ruby -r myclass -e 'p MyClass.instance_methods.sort' | Mail -s \ "This is it!" customer@somewhere.com Now I can do; % cat myinterface.rb | Mail ... :-) > class Module > def abstract(*names) > for name in names > class_eval %{def #{name}(*a) > raise NotImplementError, "#{name} not implemented" > end} > end > end > end Some "name.id2name" required? // NaHi class Module def abstract(*ids) for id in ids name = id.id2name class_eval %{def #{name}(*a) raise NotImplementError, "#{name} not implemented" end} end end alias implements include end module Stack abstract :push, :pop end class ConcreteStack; implements Stack end ConcreteStack.new.push