methods

Lists the methods of a class or object.

Category: Programming > Classes

Syntax

m = methods(obj)

Returns the method names of the class of obj as a cell array of character vectors.

m = methods('ClassName')

Does the same starting from a class name.

Description

methods tells you what you can call on an object. The list includes the constructor, whose name equals the class name, and the public methods the class defines or inherits. Hidden and private methods are left out.

With an output argument the names come back as a cell array, which is convenient for tests such as ismember('keys', methods(obj)).

Input arguments

obj
An object whose class is inspected.
'ClassName'
Name of a class on the path, as text.

Output arguments

m
Column cell array of method names, including the constructor.

Example

Checking for methods

m = methods(containers.Map);
ismember('keys', m)
ismember('remove', m)
Output
ans = logical
   1
ans = logical
   1

Notes

The list holds the methods MatLivre implements for each class, which for built-in classes such as containers.Map is shorter than MATLAB's. A class name given as text must name a class defined in a file on the path; built-in names such as 'double' or 'containers.Map' are not accepted, so pass an object instead.

See also

properties metaclass superclasses ismethod isprop