Skip to content

Instantly share code, notes, and snippets.

@keithrbennett
Created June 19, 2011 21:30
Show Gist options
  • Select an option

  • Save keithrbennett/1034784 to your computer and use it in GitHub Desktop.

Select an option

Save keithrbennett/1034784 to your computer and use it in GitHub Desktop.
Sample Contract Class
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