getmethod — Create a method-bound function handle from an object or class reference.
getmethod(receiver, name) is a RunMat-only extension that creates a callable method handle. Object and handle-object receivers are captured for later instance dispatch. Class references select static method bindings when available, or retain a qualified named-function route. Creating a handle does not execute the method.
Syntax
fh = getmethod(obj_or_class, name)Inputs
obj_or_class- Type
Any- Required
- Yes
- Default
- —
- Description
- Object receiver or class reference.
name- Type
StringScalar- Required
- Yes
- Default
- —
- Description
- Method name.
Returns
fh- Type
Any- Description
- Bound method closure/handle.
Errors
RunMat:GetMethodNameInvalid- When
- Method name is empty.
- Message
getmethod: method name must not be empty
RunMat:GetMethodReceiverUnsupported- When
- Receiver is neither object nor class reference.
- Message
getmethod: unsupported receiver
RunMat:MethodPrivate- When
- Resolved method exists but is inaccessible from the current class scope.
- Message
getmethod: method is not accessible from current scope
Inputs, output and compatibility
receiver must be a host object, handle object, or class reference. name must be scalar string text or a character row; surrounding whitespace is trimmed and the remaining name must be nonempty. Numeric and integer receivers or names reject without conversion, provider access, or gather.
Zero or one output is supported. The output is a function handle; its eventual parameter/output facts, capabilities and resolved callable identity remain runtime-dependent. The getmethod-bound-method-handle extension is rejected when RunMat extensions are disabled, with RunMat:compatibility:GetmethodExtension.
Binding and access
The current class scope controls private and protected access. An inaccessible existing method rejects with RunMat:MethodPrivate. Public methods are accessible; protected access requires a compatible caller class or subclass.
A known instance method preserves its registered semantic binding and captures the receiver. For an unknown instance member, the closure captures the receiver, trimmed method name and caller scope for the existing bound-method dispatcher; successful handle creation does not prove that later dispatch will succeed.
A class reference with a registered static method binding returns a closure without receiver captures. Other class-reference requests use the existing qualified str2func route. A handle object capture refers to the same handle; a value-object capture follows existing value semantics.
Execution and resource limits
The contextual binding retains its original BuiltinArguments throughout construction and scopes the selected RuntimeContext over registry lookup, access checks and closure creation. No alternate registry or executor is introduced.
Cancellation and revoked allocation authority are checked before cloning controls, context-scope allocation or creating captures. Closure metadata and capture backing have no exact finite-resource bound; managed invocations refuse with RunMat:Placement:InsufficientResourceEvidence rather than escaping the budget.
Construction is native/WASM host-only and outside numeric fusion. No accelerator provider, distributed execution or implicit gather is available. Invoking the returned handle is a separate operation whose actual target may suspend, throw or perform arbitrary user effects.
Examples
Create a deferred bound method handle
obj = new_object('ExampleReceiver');
f = getmethod(obj, 'compute');Reject a numeric receiver
f = getmethod(1, 'compute');Using getmethod with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how getmethod changes the result.
Run a small getmethod example, explain the result, then change one input and compare the output.
FAQ
Does a handle prove that the method exists?⌄
No. Unknown instance methods retain deferred bound dispatch, so the error may arise when the handle is called.
Does getmethod run the method?⌄
No. It constructs a handle; invoke that handle separately to run the method.
Related Introspection functions
addlistener · addParameter · addprop · assignin · builtin · cancel · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · eval · evalc · evalin · feval · findprop · func2str · functions · get.p · getcallinfo · inputname · inputParser · isa · ischar · isdeployed · iskeyword · ismethod · isobject · isstring · isUnderlyingType · isvalid · keyboard · loadobj · localfunctions · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mfilename · mislocked · mlock · munlock · namelengthmax · narginchk · nargoutchk · new_object · notify · numArgumentsFromSubscript · onCleanup · parse · saveobj · set.p · stats · str2func · subsasgn · subsref · superclasses · underlyingType · verLessThan · version · which · who · whos
Source you can read
Every RunMat function's source is public. Read exactly how getmethod is executed, line by line, in Rust.
- View the source for getmethod in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.