README.md in simplecheck-0.9 vs README.md in simplecheck-1.0rc1
- old
+ new
@@ -1,11 +1,11 @@
Simplecheck
===========
-Simplecheck is a property checking API for Ruby designed for quickly checking arguments. Once included into a class it provides the `check` instance method which takes a list of arguments and a condition to check them against.
+Simplecheck is a lightweight property checking API for Ruby designed to quickly check arguments. Once included into a class it provides the `check` instance method which takes arguments and a condition to check them against.
-If a check fails an exception of type `Simplecheck::CheckFailed` is raised.
+If a check fails a `Simplecheck::CheckFailed` exception is raised.
Usage
-----
require 'simplecheck'
@@ -35,20 +35,29 @@
* Case Equality (===) Check
* Block Check
### Expression Check
-In the simplest case `check` takes an expression as an argument. If the expression evaluates to `nil` or `false` it will fail.
+In the simplest case `check` takes an expression as an argument. If the expression evaluates to `nil` or `false` it will fail.
- check( a > 2 )
+ def calculate_percentage( score, total )
+ check( total > 0 )
+ 100.0 * score / total
+ end
### Case Equality (===) Check
If two or more arguments are given without a block, then the last argument becomes the condition against which the previous arguments are checked. To accomplish this the condition argument should implement the case equality operator (`===` or threequal) in a logical manner.
-If a class does not alias or implement it's own version of `===` it has the same functionality as `==`. The following Ruby Core classes already alias `===` to various instance methods. If a class does not alias or implement it's own version of `===` it has the same functionality as `==`.
+ def greatest_common_divisor( a, b )
+ check( a, b, Numeric )
+ # GCD Algorithm
+ end
+If a class does not alias or implement it's own version of `===` it has the same functionality as `==`. The following Ruby Core classes already alias `===` to various instance methods.
+
+
#### Class
`===` is aliased to `kind_of?`:
check( age, Numeric )
@@ -67,11 +76,11 @@
#### Proc
`===` is aliased to `call`:
- check( password, password_confirmation, lambda{ |pwd| !Dictionary.check( pwd )})
+ check( password, password_confirmation , ->(p){ !Dict.lookup( p )})
#### Custom Check Object
The default behaviour of `Object#===` is the same as `Object#==`. To customise the behaviour implement your own `Object#===` method.
@@ -82,18 +91,23 @@
### Block Check
A block can be passed to `check`, with the arguments passed to `check` then passed individually to the block:
check( a, b, c ) do |n|
- n.modulo?(2).zero?
+ n.odd?
end
This is syntactic sugar for the Proc Case Equality check.
Multiple Arguments
------------------
Case Equality and Block checks can be called with multiple arguments, with each argument being checked individually against the condition:
+
+ check( i, j, k, Integer )
+ check( a, b, c ) do |n|
+ n.even?
+ end
License
-------
Simplecheck is released under the BSD License.