0.02
No commit activity in last 3 years
No release in over 3 years
An implementation of the "abstract class" design pattern in Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

Sean Huber abstract_class

Build Status Code Climate Coverage Gem Version

Abstract classes in Ruby.

Like modules, abstract classes cannot be instantiated.

Unlike modules, abstract classes can be inherited and their derived classes can be instantiated.

Check out the java or php implementations for additional examples.

Installation

gem install abstract_class

Requirements

Ruby 1.8.7+

Usage

To make a class abstract, simply extend the AbstractClass module.

module ActiveRecord
  class Base
    extend AbstractClass
  end
end

Any attempts to initialize or allocate an instance of an abstract class raises AbstractClass::Error.

ActiveRecord::Base.new      #=> AbstractClass::Error - abstract class ActiveRecord::Base can't be instantiated
ActiveRecord::Base.allocate #=> AbstractClass::Error - abstract class ActiveRecord::Base can't be allocated

Child classes can inherit from an abstract class.

class User < ActiveRecord::Base
end

Instantiation and allocation behaves like normal for descendants of abstract classes.

User.new      #=> #<User:0x003d066d5a861d>
User.allocate #=> #<User:0x007f87588491d0>

API

YARD Documentation

Testing

bundle exec rspec

Contributing

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

License

MIT - Copyright © 2011 Sean Huber