free_mutant/lib/mutant/singleton_methods.rb
Dan Kubb ee72d6c042 Fix rubocop warnings
* Still a few more to go, but this should be the majority of them
2013-07-28 12:16:45 -07:00

28 lines
601 B
Ruby

# 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
#
def self.singleton_subclass_instance(name, superclass, &block)
klass = Class.new(superclass) do
def inspect
self.class.name
end
define_singleton_method(:name) do
"#{superclass.name}::#{name}".freeze
end
end
klass.class_eval(&block)
superclass.const_set(name, klass.new)
self
end
end # Mutant