3 Methods contain a contract that method implements and the caller
4 must adhere to. Herein are pieces of the method contract.
6 A. The method must be called with the correct number of arguments.
7 1. If a method provides a fixed number of arguments, the
8 caller must provide exactly that number of arguments.
9 2. If a method is varadic (contains a splat), then the caller
10 must provide at least the number of non-varadic arguments.
11 3. If a method contains defaults for arguments, the default values
12 will be assigned to the local variable if there is no assignment
14 4. If a method is called with the incorrect number of arguments,
15 it raises an ArgumentError to indicate the error to the caller.
16 B. If the method captures the block as a local variable, it must be
17 assigned before the body of the method begins.
18 C. As hinted to in A2, a method may provide default values for arguments.
19 The default values are evaluated in the context of the method, not the
24 A. The method provides names for each argument.
25 1. The caller may provide values for those arguments by name.
26 2. Any arguments provided by name must be provide after all
27 arguments provided by position only.
28 3. There must not be a positional value and keyword value
29 for an argument. If there is 2 values for a single argument,
30 a ArgumentError exception is thrown.
31 4. If the method specifies a varadic (splat) argument, unused
32 keywords will be stored in the splat (see E for details).
33 B. Where D is true, the splat is not a simple Array, but rather a
34 MethodArguments (MA) object. MA has a to_ary method
35 that will return the normal splat. MA also provides methods
36 for accessing unused keywords.