2013-07-28 19:03:06 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2013-01-03 18:18:48 -05:00
|
|
|
# Singleton methods are defined here so zombie can pick them up
|
|
|
|
module Mutant
|
|
|
|
|
|
|
|
# Define instance of subclassed superclass as constant
|
|
|
|
#
|
|
|
|
# @param [Class] superclass
|
|
|
|
# @param [Symbol] name
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-04-27 12:29:55 -04:00
|
|
|
def self.singleton_subclass_instance(name, superclass, &block)
|
2013-01-03 18:18:48 -05:00
|
|
|
klass = Class.new(superclass) do
|
2013-07-28 15:16:45 -04:00
|
|
|
def inspect
|
|
|
|
self.class.name
|
|
|
|
end
|
2013-01-03 18:18:48 -05:00
|
|
|
|
|
|
|
define_singleton_method(:name) do
|
|
|
|
"#{superclass.name}::#{name}".freeze
|
|
|
|
end
|
|
|
|
end
|
|
|
|
klass.class_eval(&block)
|
|
|
|
superclass.const_set(name, klass.new)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2013-06-14 14:54:02 -04:00
|
|
|
end # Mutant
|