free_mutant/lib/mutant/support/abstract.rb
Markus Schirp d50ecc483d Cleanup missing whitespace after comma
* There must be a code metric tool helping me in converting my style.
2012-07-31 04:10:37 +02:00

67 lines
1.3 KiB
Ruby

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)
class_eval(<<-RUBY, __FILE__, __LINE__+1)
def #{name}(*)
raise NotImplementedError, "\#{self.name}.\#{__method__} is not implemented"
end
RUBY
end
# Define abstract method stub on instances
#
# @param [String] name
#
# @return [undefined]
#
# @api private
#
def define_instance_method(name)
class_eval(<<-RUBY, __FILE__, __LINE__+1)
def #{name}(*)
raise NotImplementedError, "\#{self.class.name}#\#{__method__} is not implemented"
end
RUBY
end
end
end