RubyInterface 
When a class is interpreted and does not have the required methods, it throws an error.
Caveats:
- Creating anonymous classes requires the user to use
class_evalto define methods.
Installation
Add this line to your application's Gemfile:
gem 'ruby_interface'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ruby_interface
Usage
Named Classes
class SpaceShip
include RubyInterface
defines :engine, :computer
end
class Enterprise < SpaceShip
end
# => NotImplementedError, 'Expected Enterprise to define #engine, #computer'
If a class is redefined, the presence of required methods will not be checked.
Anonymous classes
class SpaceShip
include RubyInterface
defines :engine, :computer
end
space_ship = Class.new(SpaceShip)
space_ship.class_eval { }
# => NotImplementedError, 'Expected Enterprise to define #engine, #computer'
After the first class_eval, the rest of the calls to it will not check whether methods are defined.
Unfortunately, right now, class_eval has to be called to check whether the methods are defined,
pending resolution of https://bugs.ruby-lang.org/issues/12696.
Development
After checking out the repo, run bin/setup to install dependencies.
You can also run bin/console for an interactive prompt that will allow you to experiment.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/kklimuk/ruby_interface.
License
The gem is available as open source under the terms of the MIT License.