class Object # Throw a TypeError unless this object's type is cls # # @param cls The class this object should be def should_be_a(cls) raise(TypeError, "#{self.to_s} must be of type #{cls.to_s}") unless self.is_a?(cls) end end module Martin module DSL # This is just an Array that checks the type of the object being pushed to it class TypeList < Array def <<(obj) obj.should_be_a(@containing_type || Object) super end end class Method attr_accessor :block def initialize(block) block.should_be_a(Proc) @block = block end end class Configure < Method; end class Command < Method attr_accessor :regexp def initialize(regexp, block) super(block) regexp.should_be_a(Regexp) @regexp = regexp end end class Error < Method; end end end