State the example of pre- and post-conditions
Suppose that function f(x) should have a non-zero argument and return a positive value. We can document these pre- and post-conditions in comments and incorporate a check of the precondition in this function's definition, as demonstrated below
# Explanation of what f(x) computes
# @pre: x != 0
# @post: @result > 0
def f(x)
raise ArgumentError if x == 0
...
end
|