Created
June 19, 2011 21:30
-
-
Save keithrbennett/1034784 to your computer and use it in GitHub Desktop.
Sample Contract Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'instance_method_validator' | |
| module EncryptionContract | |
| def required_function_names | |
| [ | |
| # The purpose of this function is self-evident, but in other | |
| # cases the methods would benefit from some explanation | |
| # that would be helpful to authors of new implementations, | |
| # such as defining correct behavior, format and data type | |
| # of arguments and return values. | |
| # | |
| # encrypt a string | |
| # | |
| # arg: the string to encrypt | |
| # returns: the encrypted string | |
| 'encrypt', | |
| # decrypts a string | |
| # | |
| # arg: the string to decrypt | |
| # returns: the decrypted string | |
| 'decrypt', # (encrpyted string) | |
| ] | |
| end | |
| def validate_contract(klass = self.class) | |
| InstanceMethodValidator.new(required_function_names).validate(klass) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment