ismethod
Tests whether an object has a method of a given name.
Category: Programming > Classes
Syntax
tf = ismethod(obj, 'name')
Returns true if name is a method of the class of obj.
Description
Use it to decide at run time whether a call such as obj.name(...) is safe, or to write code that works with any object that offers a given operation. Inherited methods count. Properties and events do not; see isprop and events for those.
Input arguments
obj- An object.
'name'- Method name, as text. The match is case sensitive.
Output arguments
tf- Logical scalar.
Example
Methods of a Map
m = containers.Map();
ismethod(m, 'isKey')
ismethod(m, 'fly')
ismethod(m, 'Count')
Output
ans = logical
1
ans = logical
0
ans = logical
0
Notes
Pass an object. The form with the class name as text, ismethod('ClassName', 'name'), finds the methods of classes defined in files; for built-in classes such as containers.Map it does not, so pass an object there.