Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/abstract.rb

Instance Method Summary collapse

Instance Method Details

#abstract_method(args_str, *method_names) ⇒ Object

define abstract methods



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/abstract.rb', line 41

def abstract_method args_str, *method_names
  method_names.each do |name|
    module_eval <<-END
      def #{name}(#{args_str})
        mesg = "class \#{self.class.name} must implement abstract method `#{self.name}##{name}()'."
        #mesg = "\#{self.class.name}##{name}() is not implemented."
        err = NotImplementedError.new mesg
        err.set_backtrace caller()
        raise err
      end
    END
  end
end