https://github.com/shuber/abstract_class
Abstract classes in Ruby
https://github.com/shuber/abstract_class
Last synced: about 1 year ago
JSON representation
Abstract classes in Ruby
- Host: GitHub
- URL: https://github.com/shuber/abstract_class
- Owner: shuber
- License: mit
- Created: 2011-02-11T06:18:04.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2015-03-31T16:30:53.000Z (about 11 years ago)
- Last Synced: 2025-04-16T22:06:07.551Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 271 KB
- Stars: 20
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [](https://github.com/shuber) abstract_class
[](https://travis-ci.org/shuber/abstract_class) [](https://codeclimate.com/github/shuber/abstract_class) [](https://codeclimate.com/github/shuber/abstract_class) [](http://badge.fury.io/rb/abstract_class)
> 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.
[java]: http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html
[php]: http://php.net/manual/en/language.oop5.abstract.php
## Installation
```
gem install abstract_class
```
## Requirements
Ruby 1.8.7+
## Usage
To make a class *abstract*, simply extend the `AbstractClass` module.
```ruby
module ActiveRecord
class Base
extend AbstractClass
end
end
```
Any attempts to initialize or allocate an instance of an *abstract* class raises `AbstractClass::Error`.
```ruby
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.
```ruby
class User < ActiveRecord::Base
end
```
Instantiation and allocation behaves like normal for descendants of *abstract* classes.
```ruby
User.new #=> #
User.allocate #=> #
```
## API
[YARD Documentation](http://www.rubydoc.info/github/shuber/abstract_class/master)
## 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
[MIT]: https://github.com/shuber/abstract_class/blob/master/LICENSE