Sha256: 8c8cdd28b2e4382cbb8588619dd6a3e2c6e8577d75c5f899ab9a0cf8a43d3580

Contents?: true

Size: 529 Bytes

Versions: 60

Compression:

Stored size: 529 Bytes

Contents

class Class
  # 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
  def subclass(base_name, &body)
    klass = Class.new(self)
    class_name = "#{base_name}_#{class_count!}"
    instance_eval do
      const_set(class_name, klass)
    end
    klass.instance_eval(&body)
    klass
  end

  private
  def class_count!
    @class_count ||= 0
    @class_count += 1
    @class_count
  end
end

Version data entries

60 entries across 60 versions & 10 rubygems

Version Path
dchelimsky-rspec-1.1.10 lib/spec/extensions/class.rb
dchelimsky-rspec-1.1.11.1 lib/spec/extensions/class.rb
dchelimsky-rspec-1.1.11 lib/spec/extensions/class.rb
jnstq-acts_as_sms-0.1.0 test/vendor/plugins/rspec/lib/spec/extensions/class.rb
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec/lib/spec/extensions/class.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec/lib/spec/extensions/class.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec/lib/spec/extensions/class.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/extensions/class.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/extensions/class.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/extensions/class.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/extensions/class.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/extensions/class.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/extensions/class.rb
mack-0.8.2 lib/gems/rspec-1.1.11/lib/spec/extensions/class.rb
picolena-0.0.99 app_generators/picolena/templates/vendor/plugins/rspec/lib/spec/extensions/class.rb
picolena-0.1.1 rails_plugins/rspec/lib/spec/extensions/class.rb
picolena-0.1.0 rails_plugins/rspec/lib/spec/extensions/class.rb
picolena-0.1.2 rails_plugins/rspec/lib/spec/extensions/class.rb
picolena-0.1.4 rails_plugins/rspec/lib/spec/extensions/class.rb
picolena-0.1.3 rails_plugins/rspec/lib/spec/extensions/class.rb