2012-07-30 22:00:05 -04:00
|
|
|
module Mutant
|
|
|
|
# Module to declare abstract methods
|
|
|
|
module Abstract
|
|
|
|
|
|
|
|
# Declare abstract instance method
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def abstract(*names)
|
|
|
|
names.each do |name|
|
|
|
|
define_instance_method(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
# Declare abstract singleton method
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def abstract_singleton(*names)
|
|
|
|
names.each do |name|
|
|
|
|
define_singleton_method(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Define abstract method stub on singleton
|
|
|
|
#
|
|
|
|
# @param [String] name
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def define_singleton_method(name)
|
2012-07-30 22:10:37 -04:00
|
|
|
class_eval(<<-RUBY, __FILE__, __LINE__+1)
|
2012-07-30 22:00:05 -04:00
|
|
|
def #{name}(*)
|
2012-07-30 22:10:37 -04:00
|
|
|
raise NotImplementedError, "\#{self.name}.\#{__method__} is not implemented"
|
2012-07-30 22:00:05 -04:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
# Define abstract method stub on instances
|
|
|
|
#
|
|
|
|
# @param [String] name
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def define_instance_method(name)
|
2012-07-30 22:10:37 -04:00
|
|
|
class_eval(<<-RUBY, __FILE__, __LINE__+1)
|
2012-07-30 22:00:05 -04:00
|
|
|
def #{name}(*)
|
2012-07-30 22:10:37 -04:00
|
|
|
raise NotImplementedError, "\#{self.class.name}#\#{__method__} is not implemented"
|
2012-07-30 22:00:05 -04:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|