Class | Class
In: | lib/spec/extensions/class.rb
Parent: | Object

### Methods

subclass

### Public Instance methods

subclass(base_name, &body)

Creates a new subclass of self, with a name "under" our own name. Example:

      x = Foo::Bar.subclass('Zap'){}
      x.name # => Foo::Bar::Zap_1
      x.superclass.name # => Foo::Bar

[Source]

        # File lib/spec/extensions/class.rb, line 8
     8:   def subclass(base_name, &body)
     9:     klass = Class.new(self)
    10:     class_name = "#{base_name}_#{class_count!}"
    11:     instance_eval do
    12:       const_set(class_name, klass)
    13:     end
    14:     klass.instance_eval(&body)
    15:     klass
    16:   end

[Validate]