From: James Edward Gray II Date: 2007-07-12T23:45:03+09:00 Subject: Re: Abstract methods in ruby ? On Jul 12, 2007, at 9:17 AM, Robert Dober wrote: > On 7/12/07, James Edward Gray II wrote: > >> > 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] >> >> class AbtractClass >> REQUIRED_METHODS = %w[one two three] >> >> def self.inherited(subclass) >> REQUIRED_METHODS.each do |m| >> raise "An implementation of #{m} is required by # >> {self.class}" \ >> unless subclass.instance_methods.include? m >> end >> end >> end >> >> class Broken < AbtractClass >> def one; end >> def two; end >> end >> # ~> -:7:in `inherited': An implementation of one is required by >> Class (RuntimeError) >> # ~> from -:5:in `each' >> # ~> from -:5:in `inherited' >> # ~> from -:12 >> >> But don't do that. ;) > That does not work as you have intended, it is complaining about #one > missing as a matter of fact: You are right. My mistake. James Edward Gray II