Description =========== Java style interfaces for Ruby. Synopsis ======== require "interface" MyInterface = interface{ required_methods :foo, :bar, :baz } # Raises an error until 'baz' is defined class MyClass def foo puts "foo" end def bar puts "bar" end implements MyInterface end Constants ========= Interface::VERSION Returns the current version number of this package as a String. Methods ======= extends(module) An alias for 'extend'. implements(module) An alias for 'include'. Syntactic sugar for the Java folks. :) interface(&block) Accepts a block. There are only two methods you should ever pass to this block: required_methods and/or unrequired_methods. Subinterfaces will need to 'extend' their parent interface. Module Methods ============== Interface.required_methods(:method1, :method2, ...) Accepts an array of method names that define the interface. When this module is included/implemented, those method names must have already been defined. Interface.unrequired_methods(:method1, :method2, ...) Accepts an array of method names that are removed as a requirement for implementation. Presumably, you would use this in a subinterface where you only wanted a partial implementation of an existing interface. Error classes ============= Interface::MethodMissing Raised if a class or instance does not meet the interface requirements. Notes ===== Subinterfaces work as well. See the test_sub.rb file under the 'test' directory for a sample. Acknowledgements ================ This module was largely inspired and somewhat copied from a post by David Naseby at http://homepages.ihug.com.au/~naseby/33.html. It was subsequently modified almost entirely by Mauricio Fernandez through a series of discussions on IRC. Copyright ========= (C) 2004 Daniel J. Berger All rights reserved. Warranty ======== This package is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose. License ======= Ruby's Author ====== Daniel J. Berger (who mostly stole it from David Naseby, which was then modified by Mauricio Fernandez) djberg96 at yahoo dot com rubyhacker1/imperator on IRC