Dodo doc > Types > Constructors and Methods > Instance Methods
Methods are similar to functions with the addition that they can be overloaded to allow multiple argument lists. Methods build an object as their return value. While functions are generally stateless methods are generally stateful.
A method name follows the same syntax as a type name. It must start with an upper case letter and can contain letters, digits and underscore "_".
Examples:
Reset
Play
Start_process
A method declaration starts with "method" followed by the method name and its parameter types. If the method has a return type or more than one set of parameters, then the method name must be followed by a declaration block.
Inside the declaration block, the method can have different bodies each with its own set of parameters. A method body declaraction starts with "make" then a function name followed by the list of parameters, much in the same way a constructor is declared (see section on constructors). In fact, a method declaration block is the same as a type declaration with constructors. A method does not have a default value.
There can be other declarations in the method declaration block which are accessed via the "self" variable inside a method body. When member variables are declared, they serve as the return values of the method.
Examples:
method Mix(&Fruit[], SpeedSetting?)
method Play
{
make sound(Sound, *Output, Player.Options?)
make show(Video, &Window, Player.Options?)
enum result
}
A method invocation uses the dot to connect the object variable with the method name. The method name is followed by the list of arguments. An empty list of arguments is written with empty brackets.
A method can only be invoked on a variable reference. It can be a variable declared in the scope or an argument passed by reference. Methods cannot be used on constants.
To read the attributes of the object built by the method, the result of method invocation can be saved into a variable. This is a way to handle multiple return values.
Examples:
foodProcessor.Mix(.fruits, 9)
player.Reset()
def play = player.Play(mp3stream, *soundOut, [:low_latency, :simple_convol])