RAA - constraint/0.1

constraint / 0.1

Short description: Ensure that object always satisfy a specified set of constraint
Category: Library/Datastructure
Status: experimental
Created: 2005-06-10 17:33:46 GMT
Last update: 2005-06-10 17:33:46 GMT
Owner: tlink (Projects of this owner)
Homepage: http://constraint.rubyforge.org/
Download: http://rubyforge.org/frs/?group_id=748
License: Ruby's
Dependency:
None
Description:

This library provides a way to ensure that object always satisfy a specified set of constraints. An object that can be constrained must be of kind Constraint::Shell. Constraints can be added to classes and single objects. It is possible to define methods that handle constraint violations and can make the object fit the demands.

class EvenInteger < Constraint::Shell
and_constraint("Numeric") {|e| e.kind_of?(Integer)}
and_constraint("Even") {|e| e.modulo(2) == 0}
end

enum = EvenInteger.new(2)
enum.and_constraint("LT10") {|e| e < 10}

(enum + 2).constrained_value
=> 4
enum + 1
=> `check_constraints': Class: Fixnum didn't meet constraints (Numeric, Even): 3 (ConstraintViolation)

Versions: [0.2 (2005-06-15)] [0.1 (2005-06-10)]

Edit this project (for project owner)

back to RAA top